1
votes

Front end application will use firebase.com as database. Application should work like blog:

Admin add / remove posts.

There are "home" page which show several articles per page with "Next" and "Prev" buttons and page which show single article.

Also I need deep linking. I.e. when user enter URL http://mysite.com/page/2/ I need that application show last articles from 10 to 20, when user enter URL http://mysite.com/page/20/ application show last articles from 200 to 210. Usual pagination.

Main question - is it possible to achieve this if use firebase.com.

I read docs at firebase.com, I read posts here. "offset()" and "count()" will be in the future, use priority, in order to know count of items and not load all of them use additional counter.

Based on this I suppose this:

  • ADD POST action:

    1. get value of posts counter
    2. set priority for new post data equals to value of posts counter
    3. increase value of posts counter
  • DELETE POST action

    1. get value of priority for post data
    2. query posts data which have value of priority more than priority for post data which will be deleted and decrease their value
    3. decrease value for posts counter
  • GET POSTS FROM x TO y

    1. postsRef.startAt(null, x).endAt(null, y).on(... and so on)

Thing which I not like in this way are actions for DELETE POST. Because index of posts will be from 0 to infinity and post with less priority is considered as post which was created earlier so if I have 100000000 posts and if I need to delete 1st post then I need to load data for 99999999 next posts and update their priority (index).

Is there any another way?

Thanks in advance, Konstantin

1

1 Answers

2
votes

As you mentioned, offset() will be coming, which makes your job easier.

In the meantime, rather than using startAt and endAt in combination, you could use startAt and limit in combination to ensure you always get N results. That way, deleted items will be skipped. You then need to check the last id of each page before moving to the next to find the proper id to start on.