问题
We are building a job portal. We have a applications collection where we create a document when a user applies for a job.
Now, from Android app client, I am listening to the same collection in two different activities. I have enabled the local persistence too.
Now, does Firebase understand that it is the same query triggered from two activities and maintains one query snapshot for the listener or does it create two snapshots?
回答1:
Now, does the Firebase manages to understand its the same query happening from two activities and maintains one query snapshot for the listener or it creates two snapshots?
Since you say that you have enabled the local persistence, it means that Firebase will create a local copy of the requested documents on the user's device. So with this persistence enabled, while offline, it doesn't really matter the number of activities from which you perform the same query, you'll always get the data from the cache.
As @brianbhsu pointed out in his comment, while online, you'll always query the online Firestore instance so you'll always have the data up to date.
As also Frank van Puffelen mentioned in his answer, Firestore doesn't store all available data locally automatically:
- How does Firestore persistence really work?
@Mangesh If you query from two different activities using two different Query objects, then those queries will be treated as two different queries.
来源:https://stackoverflow.com/questions/57051635/firestore-if-two-listeners-listening-the-same-query-firebase-maintains-two-diff