Firestore集合侦听器读取次数众多 [英] Firestore collection listeners enormous number of reads

查看:45
本文介绍了Firestore集合侦听器读取次数众多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在其中一个应用程序中实现Firestore数据存储.

I am implementing Firestore data storage in one of my apps.

我有一个侦听器,它遵循"logs"集合中的更新,如下所示:

I have a listener which follows updates in the "logs" collection like so:

db.collection("logs").addSnapshotListener({ (snapshot, error) in
    guard let s = snapshot else {return}
    if s.metadata.isFromCache {
        print("LOG_C \(s.documentChanges.count)")
            return
    }
    print("LOG \(s.documentChanges.count)")
    // other code
})

在测试过程中,我一直在将文档上传到此收藏集中,然后通过Firebase控制台删除了所有文档.因此,目前,我的测试用户不存在该集合.首次启动该应用程序时,确实看到该集合为空-侦听器报告正确的结果.

During testing, I've been uploading documents to this collection and then I removed all of them through Firebase console. So, right now, the collection doesn't exist for my test user. When I launch the app for the first time, I do see that this collection is empty - the listener reports the correct result.

但是,这样做会消耗大约1000次读取.几乎感觉就像是要为我的测试用户下载该收藏集的所有历史记录(例如,插入500个文档,删除500个文档).但是,即使这样做,它也不会向我报告-我在控制台中仅收到一条"LOG 0"消息.

However, in doing so, it consumes roughly 1000 reads. It almost feels like it is downloading all the history of this collection for my test user (e.g. 500 docs inserted, 500 docs deleted). However, even if it does, it does not report it to me - I receive only one "LOG 0" message in the console.

这是集合侦听器的工作方式吗?我确实知道侦听器会下载初始状态,但是我认为这将是当前快照,在这种情况下,它将消耗1次读取以确定最初没有返回任何内容.

Is this how collection listeners work? I do know that listeners download the initial state, but I thought that it would be the current snapshot which, in this case, would consume 1 read to determine that there is nothing to return initially.

欢迎任何解释/想法/建议.

Any explanations/ideas/suggestions are welcome.

我非常想通过查看详细的Firestore读取日志进行调试.但是,我在控制台中找不到这样的选项:(

I would very much like to debug this by viewing detailed Firestore read logs. However, I cannot find such option in the console :(

推荐答案

在这种情况下,听起来好像OP在执行数据库操作时将Firestore控制台保持打开状态.由于Firestore控制台本身会反映实时更新,因此随着当前所选集合的更改,它将随着时间的流逝而产生读取.

In this case, it sounds as if the OP left the Firestore console open while performing database operations. Since the Firestore console itself reflects realtime updates, it will incur reads over time as the currently selected collection changes.

这篇关于Firestore集合侦听器读取次数众多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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