Firestore: If two listeners listening the same query firebase maintains two different query snap shots?

社会主义新天地 提交于 2020-08-09 12:28:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!