Page pagination in an application using firebase.com as a database

The Front End application will use the firebase.com database. The application should work like a blog:

Admin adds / removes messages.

There is a "home" page that shows several articles on a page with the "Next" and "Prev" buttons and pages that show a separate article.

I also need deep binding. That is, when the user enters the URL http://mysite.com/page/2/ I need the application to display the latest articles from 10 to 20, when the user enters the URL http://mysite.com/page/20/ the application shows the latest Articles from 200 to 210. Normal pagination.

The main question is whether this can be achieved using firebase.com.

I read documents on firebase.com, I read messages here. "offset ()" and "count ()" will be in the future, use priority to find out the number of elements and not load all of them using an additional counter.

Based on this, I assume the following:

  • ADD POST action:

    • get message counter value
    • set priority for new message data equal to message counter value
    • increase message counter value
  • DELETE POST action

    • get priority value for post data
    • request message data that have a priority value is higher priority for post-data to be deleted and reduced.
    • decrease value for message counters
  • GET POSTS FROM x TO y

    • postsRef.startAt (null, x) .endAt (null, y) .on (... etc.)

Things I don't like are actions for DELETE POST. Since the message index will be from 0 to infinity, and the post with the lower priority is considered to be the post that was created earlier, therefore, if I have 100,000,000 posts, and if I need to delete the 1st post, I need to load data for 99999999 of the following messages and update their priority (index).

Is there another way?

Thanks in advance, Konstantin

+1
firebase
May 18 '13 at 19:50
source share
1 answer

As you already mentioned, it will shift (), which will simplify your work.

At the same time, instead of using startAt and endAt in combination, you can use startAt and restrict the combination to ensure that you always get N results. Thus, deleted items will be skipped. Then you need to check the last identifier of each page before moving on to the next to find the correct identifier to start with.

+2
May 20 '13 at 16:08
source share
โ€” -



All Articles