Firestore Pagination logic - Show page number

216 views
Skip to first unread message

Jean Omberto

unread,
Oct 3, 2022, 1:45:13 PM10/3/22
to fireba...@googlegroups.com
Dear Frank and everyone,
I have implemented pagination in a project using the method startAfter.
The Query comprises the result between 2 dates and limited to 50 .
My question is : In case i  have 5000 records to paginate, that makes it 100 pages to navigate, how can i show the user on which page they are at?
Example Page 3 of 100.
Do I have to start by querying the database to give me that snapshot size of 500 then keep a reference to the size and finally build my second query with limit 50 ? 

If so, will I pay for both queries ? (The first one to get the overall snapshot size and the second one which is the navigable query to be limited to 50 ).
If there is a better, concise and economic way, please let me know.

Thanks,
Jean  

Tracy Hall

unread,
Oct 5, 2022, 3:29:51 PM10/5/22
to Firebase Google Group
Firestore *really* doesn't have the concept of "pages" - just "startAfter", "endBefore" and things like that.  Since asynchronous writes *could* add records into your results, trying to treat things like "fixed pages" is really going to lead to a world of hurt.

Better to accept the asynchronous nature and use more "indexing" like references (somewhat like the spines of a set of encyclopedias - "Roger, Francis" -to- "Stuart, Little", for example; or in your case "May 5, 1973" -to- "March 27, 1978")

Tracy Hall
Reply all
Reply to author
Forward
0 new messages