Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase: Listening to multiple user nodes

I'm working on an app using Firebase and Geofire. On running the Geo query at the current location, let's say I receive 10 keys in the OnKeyEntered override method. Each of these keys is essentially a user node in Firebase. I need to listen to each of the user in the query area for any data change so that I can show updates on the map in realtime.

Currently, I'm adding a ValueEventListener for every key entered but I'm not sure if starting so many listeners at the same time is good idea. The users in the query area can potentially be more than 50. That means I could have 50 open listeners!

Is there a better way to go about it? I was trying to figure out a firebase query to filter on only the geo query keys but was unsuccessful.

Any help would be great!

like image 252
Kashif Avatar asked Jan 28 '23 20:01

Kashif


1 Answers

Listeners are not computationally expensive, unless you have one that's going to be triggered very frequently because the data it's listening to is changing often.

Don't fall into the trap of optimizing your code before you actually observe a need to optimize it. When you see that performance is poor, that's the time to make optimizations. If you need a bunch of listeners to get your work done, go ahead and do that. Just know what your practical upper bound it, and be sure to test that upper bound for problems.

like image 94
Doug Stevenson Avatar answered Jan 31 '23 11:01

Doug Stevenson