I have a firebase structure that looks like this:
<root>
|-my-app-name
|-post
|-<uid1>
|-negatedtimestamp
|-sub nodes
|-...
|-<uid2>
|-negatedtimestamp
|-sub nodes
|-...
I have my pagination done by limitToFirst(10)
and orderbyChild("negatedtimestamp")
to retrieve the recent 10 items. The last uid is saved, and was queried again at loadmore() with startAt(<uid>)
.
In term of scalability, when the node post grow to ten or hundred of thousands, query the first/last 10 will leads to slower time as it is asking the database to consider all of the nodes. There is a solution for this by storing only the keys of recent 10 items in another nodes, retrieve them, and read directly from the parent node. This was suggested at here:https://stackoverflow.com/a/39713060/9088278
However, in order to perform pagination, the recent 10 node is changing when loadmore()
function is hit as it needs to load the older 10, then older 10 again. How can I do pagination by this way? Or is there any alternative?