I'm seeing terrible update frequency when resuming the app after it had been in the background for a while. If I kill and re-launch the app from scratch it'll usually query the most recent data fine. Similarly, when I first start listening for snapshots it works as expected, receiving data as soon as the firestore data is updated.
It is only after the app has been in the background for too long (say 1-2 hours) and I reopen it that I see the query return cached data but not receive an update from the network for 30-90 seconds.
Here's my query:
firestore.collection(GAMES_COLLECTION)
.whereGreaterThanOrEqualTo("time_utc", start)
.whereLessThanOrEqualTo("time_utc", end)
.orderBy("time_utc")
.addSnapshotListener { snapshot, e ->
val games = snapshot.map { doc -> doc.toObject(GameEntity::class.java) }
}
The "Game" document is not too complex either (19 primitive fields and 1 array field that has 0-3 elements)
The "time_utc" field is an int that has one of the automatic indexes enabled (ascending/descending)
I've tried subscribing in a couple of different ways to see if that's the problem but I really doubt that's the problem given that it's not a problem of the subscription being lost or something, if I stay for long enough (1 minute) I'll eventually get an update. I'm subscribing on jetpack's ViewModel's init and unsubscribing in onCleared() (i.e. fragment's onCreate/ onDestroy).
I also tried having a single "global" subscription (started in the Application class' onCreate()) in case it was a "cold start" issue but that doesn't work either.
Also tried using .get().addOnSuccessListener() on that same query through a manual refresh when I know the data is stale and I'm not getting network updates but it immediately returns the same cached data.
Offline persistence is enabled, I have not setup any caching limits.
Using firestore 21.5.0
from Android's Firestore's snapshot listener on query takes too long (1 min) to update from the network when returning from being in the background
No comments:
Post a Comment