问题描述
当我不需要侦听更改时,我希望能够停止快照侦听器,以便以后可以一次获取所有更新.是否可以暂时停止快照侦听器?我认为您必须明确删除它,然后根据文档重新初始化所有内容.因此,我可以显式调用remove并重新初始化快照侦听器以获取更改,但是这样做会带来一定的代价吗?我知道在30分钟内读取缓存的值不会花费任何费用,这是否意味着连接和分离快照侦听器也不会花费任何费用?
I want to be able to stop snapshot listener when I don't need to listen for changes so later I can get all the updates at once. Is it possible to temporarily halt the snapshot listener? I think you have to remove it explicitly and reinitialize everything according to the doc. So I can explicitly call remove and reinitialize the snapshot listener to get changes, but is there a price penalty for doing this? I know reading cached values within 30 minutes doesn't cost anything, so does this mean it wouldn't cost anything to attach and detach the snapshot listener?
如果文档没有更改,并且我在30分钟内将快照侦听器连接了50次以上,那会花我什么钱吗?
If a document has no changes, and I attach the snapshot listener over and over say 50 times in 30 minutes, would that cost me anything?
推荐答案
否,如果您的数据库中没有更改,则监听器将不启动.但是,如果分离侦听器并再次附加它,则将花费,即使查询未返回任何结果.根据弗兰克·范·普菲伦(Frank van Puffelen)的评论,这是它如此工作的原因:
No, the listener will not fire if there are no changes in your database. However, if you detach the listener and you attach it again, there is a cost of one document read, even if the query returns no results. According to Frank van Puffelen's comment, here's the reason why it works that way:
这真的很有意义.
是的,这是正确的.当不再需要该侦听器时,只需将其分离即可.
Yes, that's correct. When the listener is no more needed, simply detach it.
您始终需要为阅读的文档数付费.例如,如果查询返回两个文档,则将向您收取两次文档读取费用.如果没有结果,则只需要执行一次读取操作即可计费.
You'll always be billed for the number of documents that you read. For instance, if your query returns two documents, you be billed with two document reads. If you get no results, you only be billed with a single read operation.
如果文档没有更改,并且我在30分钟内将快照侦听器重复安装了50次以上,那会花我什么钱吗?
If a document has no changes, and I attach a snapshot listener over and over say 50 times in 30 minutes, would that cost me anything?
如果分离侦听器并附加一个新侦听器50次,并且数据库中没有任何更改,则将花费50次文档读取.
If you detach the listener and attach a new one for 50 times, and if there are no changes in the database, it will cost you 50 document reads.
这篇关于Firebase在30分钟内没有任何更改时,是否需要多次附加和分离SnapshotListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!