0

I am starting a new firebase project and using ionic to make it a hybrid app. This is a learning experience for me, that will hopefully grow into a full on app. For the time being I am trying to figure out how to get a batch of users at once. Let say my app allows people to "follow" other people, like IG for example. So I have a database called "following" in that database there are user ids, each user id will have a key called "users" which will list out all of the users that that user is following...

{
  "following" : {
    "$userID": {
      "count": 2,
      "users": {
        "$userID": true,
        "$userID": true
      }
    },
    ...
  }
}

Obviously the "$userID" would be a real user ID. Now if a user has something like 100 followers, I would have a long list of user IDs. I am trying to find a way to get all of those users from the "users" table in one go, rather than having to make 100 individual database calls, or 1 for each user. I can't find anything in the documentation that shows how to get a batch of items except for startAt or endAt, but neither of those apply, since they will be random user ids, and not a sequential list. Making 100 (or even 1k or more) individual calls to the database seems extremely inefficient. Is there any way to get a batch of results? If you need it, the user ID is the $key from the "/users" table, so the database calls would be something like...

this.db.database.ref('/users/' + userID).once('value', (snapshot) => { ... }); Thank you for any help in advance.

Neglected Sanity
  • 1,770
  • 6
  • 23
  • 46
  • Firebase pipelines requests, so separate calls are not as expensive as you might think they are: https://stackoverflow.com/a/35558767/6680611 – cartant Jul 29 '17 at 01:06
  • There is no Firebase Database equivalent for `SELECT * FROM users WHERE id IN (4,8,15,16,23,42)`. For reasonable numbers of items this also would make a significant difference, since Firebase pipelines the request over a single connection. See my answer here for more: 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 Jul 29 '17 at 01:08

0 Answers0