Ameenah Burhan
Ameenah Burhan

Reputation: 36

Should I use queries in firebase or the observe functions?

I am building out an iOS app that requires getting lists of users at different parts of the app(finding users nearby, find users that have similar interest etc) I'm displaying the list of users in collection views/table views.

I have a user structure that contains all of the user data(name, photo, list of interest, location, preferences..etc)

My question is, when I'm getting the list of users from the database, is it more cost effective to use the query function or to use the observe functions? In the list I only need to display the users photo and username. If the user wants to find out more then clicking on the cell will get more data from the larger user data table.

My options

  1. using a query to get the users that meet the criteria for that list(say all users nearby). Then when the user clicks on the cell that interests them, get a snapshot from the database for that specific users. My thought process is its less costly than pulling back the whole snapshot using the observe functions.

  2. using the observe functions, getting all users snapshot data and only displaying the photo and username. If the user selects a cell send the data to the detail view.

  3. creating a special display structure that contains only items necessary for the collection view/ table view and if the user clicks on a cell call the database again getting all of that users data.

If anyone has a point of view they could share that would be great! Thanks

Upvotes: 2

Views: 103

Answers (1)

Observing in Firebase needed for making instant update, like in chats, when new message appear you need to update message list. So here, for getting list of users that fit your request, better to use queries

Upvotes: 1

Related Questions