Firestore:如果两个侦听器正在侦听同一查询,那么Firebase是否维护两个不同的查询快照? [英] Firestore: If two listeners listening the same query firebase maintains two different query snap shots?

查看:57
本文介绍了Firestore:如果两个侦听器正在侦听同一查询,那么Firebase是否维护两个不同的查询快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在建立工作门户.我们有一个 applications 集合,当用户申请工作时,我们会在其中创建一个文档.

We are building a job portal. We have a applications collection where we create a document when a user applies for a job.

现在,从Android应用程序客户端中,我正在通过两个不同的活动收听同一收藏集.我也启用了本地持久性.

Now, from Android app client, I am listening to the same collection in two different activities. I have enabled the local persistence too.

现在,Firebase是否了解这是两个活动触发的同一查询,并为侦听器维护一个查询快照,还是创建了两个快照?

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?

推荐答案

现在,Firebase是否能够理解来自两个活动的相同查询,并为侦听器维护一个查询快照,还是创建两个快照?

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?

由于您说已启用了本地持久性,因此Firebase将在用户设备上创建所请求文档的本地副本.因此,启用此持久性后,即使在脱机状态下,执行相同查询的活动数量也无关紧要,您始终可以从缓存中获取数据.

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.

@brianbhsu在评论中指出,在线时,您将始终查询在线Firestore实例,以便始终获取最新数据.

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.

Frank van Puffelen在回答中也提到,Firestore不会自动在本地存储所有可用数据:

As also Frank van Puffelen mentioned in his answer, Firestore doesn't store all available data locally automatically:

@Mangesh如果使用两个不同的 Query 对象从两个不同的活动中进行查询,则这些查询将被视为两个不同的查询.

@Mangesh If you query from two different activities using two different Query objects, then those queries will be treated as two different queries.

这篇关于Firestore:如果两个侦听器正在侦听同一查询,那么Firebase是否维护两个不同的查询快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆