Managing data connection use with Firebase / Set Update Rate

Automatic syncing with Firebase data is fantastic. But I’d like more control over when the updates happen.

My app has used 400kB of data in the last several hours while the phone screen has been off and the app was running in the background. I’d like it to only update data when the app is in active use.

More generally, is there any control over the update rate?

Could you point me toward some docs regarding how to make efficient use of the data connection?


Just unsubscribe from the Observables you define. If you want a simple rule, don’t have any active listeners except the ones on the currently active page. A slightly more sophisticated rule would be to subscribe to Platform.pause, and to unsubscribe from all streams whenever your app pauses.

Thanks, Aaron. Suppose that a subscription is created when Function A runs and Function A has some event handling whenever the data changes.

Later, Function B unsubscribes what Function A subscribed to.

Is there a way to re-instate the subscription without re-calling Function A such that Function A resumes its behavior where it left off? Or is it best practice to always organize the program such that Function A will be re-called?

It depends. But as a general rule, only have one place in your app where you can gain access to a stream. If multiple pages need access to a stream, first question to ask yourself is: do they really? Or do you only need one copy of the original data that is multicast to various locations.

Slightly different topic:

I have a synchronizer provider that updates the local state when the Firebase realtime database updates. It contains “start synchronizing with stream X” and “stop synchronizing with stream X” methods for different slices of state X, Y, Z, etc. Logging in or opening a particular page calls the appropriate synchronizers, while logging out calls all the stop-synchronizers. More or less, only the synchronizer provider touches the Firebase streams, and all Observables on pages ask questions of the local copies of the data. That way, almost all queries are cheap, and I’m only making an expensive query when I have to.

1 Like