https://kotlinlang.org logo
#getting-started
Title
# getting-started
t

Tariyel Islami

05/20/2022, 9:27 AM
Hi guys, I am pulling data from firestore. When I need to sort these data by name or id numbers, do I need to pull them again from firestore or should I sort my list? When I look at a few places on the internet, it pulls from the firestore. Which is the right approach?
t

tseisel

05/20/2022, 11:25 AM
It's almost always better to request data from Firestore already sorted, especially if you are requesting a large collection or would like paginated results.
t

Tariyel Islami

05/20/2022, 1:30 PM
Hi @tseisel Thank you for answer, Yes, I can guess that, but why is it better to pull the data again in order instead of sorting the data that I have already pulled once?
t

tseisel

05/20/2022, 2:46 PM
If you already have fetched the unsorted data, it would be wasteful to request Firestore again just to sort the same data.
a

Advitiay Anand

05/22/2022, 1:47 PM
Why don't you just request the data once as sorted? The upside is that you don't have to waste the client device's resources doing any more processing on the fetched data.
t

Tariyel Islami

05/23/2022, 12:09 PM
@Advitiay Anand For example, in case he wants to sort by name, age, id number.
a

Advitiay Anand

05/23/2022, 12:37 PM
Right. It actually depends on how big the data is, and how costly it is to sort it. If you're building a small project then it does not matter. Just sort it on the device. However, if the data is quite large, then you should keep it sorted / filtered on the backend, and simply make paginated requests. Try to save the user from any possible lags.
t

Tariyel Islami

05/23/2022, 4:47 PM
I thought it was like that too Many tutorials on the Internet were pulled directly from the database. That’s why I wanted to confirm my opinion. Thanks for your answers.
👍 1
11 Views