0

I create an android application that uses firebase. In my application, users can follow other users. (Like twitter). Users can write posts. I would like, for a user, that he can retrieve the last posts of the people that it follows. I have been looking for several days but I can not find a design that would allow me to do this.

I thought of a few things like this:

"user":{
   "Alize":{
      "nom":"Alize",
      "follow":{
         "franck":true
       }
   "franck":{
       "nom":"franck"
   }
}
"post":{
     "franck":{
       "-APUH45599D":{
         "titre":"blablabla,
         "author":"franck,
         "date":"21025522402"
       }
     }
}

But if i want, for a user, get last posts of the following people, this require one requete for each following people, and i can't order by date...

Someone would have an idea ? Thank you ! (Sorry for my english)

montauvergne
  • 175
  • 3
  • 9
  • Requesting multiple items from the Firebase Database is not as slow as you may think in this scenario. See http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen Dec 10 '16 at 19:17
  • Thank you for your reply. But if I want to retrieve the last 10 posts. I should sort all posts retrieved by user, and it can be long... – montauvergne Dec 10 '16 at 19:47
  • You'll either need to retrieve extra data and sort/filter client-side *or* store additional data in the database to allow the sort/filter server-side. E.g. `/Alize/follow/franck: 21025522402`. With this structure for the followers, you can order them by date using `ref.child("user/Alize/follow").orderByValue()` – Frank van Puffelen Dec 10 '16 at 19:55
  • With this structure I would be obliged to add the posts, in each of the users/"Name"/follow for all the users. And the database would be huge. Or maybe I did not understand. Let's imagine that franck to create two post and a third user, let's say Anna, create one posts. (Alize follows anna). With this technique I would not be able to retrieve the three posts in chronological order, am I wrong? – montauvergne Dec 10 '16 at 20:09
  • You seem to come from a relational mindset. I recommend reading [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/) and viewing [Firebase for SQL developers](https://www.youtube.com/playlist?list=PLl-K7zZEsYLlP-k-RKFa7RyNPa9_wCH2s). – Frank van Puffelen Dec 11 '16 at 06:09

0 Answers0