I am currently thinking about how I can implement pagination with firebase. I understand how to paginate data ordered by a static value like for example the timestamp of a post. You just limit the query to a specific amount (for example 5 posts), save the last items static value (for example the timestamp) and then repeat the query again, starting at the last items static value (timestamp). But what happens when you want to paginate by a child which value is constantly changing? Like for example data sorted by a child: "rating". Where the "rating" can change at any moment as other users are rating constantly. Therefor the first 5 posts queried might not be the 5 best rated posts anymore when I query the second 5 posts. In addition to that I am not able to find a reliable start or ending point of the query as the values are constantly changing.
0
votes
1 Answers
0
votes
Let's say you have a query of the top 5 rates posts:
id: a, rating 5.0
id: b, rating 4.9
id: c, rating 4.8
id: d, rating 4.7
id: e, rating 4.6
This is a live query, so it updates as the underlying data changes. Say that somebody gives item c a very low rating so that its average becomes 4.0. This means that c disappears from the query snapshot, and the next highest rated item gets pulled in, resulting in:
id: a, rating 5.0
id: b, rating 4.9
id: d, rating 4.7
id: e, rating 4.6
id: f, rating 4.5
So you still have 5 items in the result set.
In terms of pagination, the last item of this new page is still the anchor for the next page too.