Firebase在30分钟内没有任何更改时,是否需要多次附加和分离SnapshotListener? [英] Firebase Does it cost to attach and detach SnapshotListener many times when there are no changes within 30 minutes?

查看:48
本文介绍了Firebase在30分钟内没有任何更改时,是否需要多次附加和分离SnapshotListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我不需要侦听更改时,我希望能够停止快照侦听器,以便以后可以一次获取所有更新.是否可以暂时停止快照侦听器?我认为您必须明确删除它,然后根据文档重新初始化所有内容.因此,我可以显式调用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?

推荐答案

Firebase在30分钟内没有任何更改时,是否需要多次附加和分离SnapshotListener?

Firebase Does it cost to attach and detach SnapshotListener many times when there are no changes within 30 minutes?

否,如果您的数据库中没有更改,则监听器将启动.但是,如果分离侦听器并再次附加它,则将花费

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:

服务器需要代表您执行查询,因此,如果服务器上没有正在读取的单个文档,则会向您收取查询费用(实际上是读取索引),以防止不断的分离/重新连接(这会耗尽服务器的资源)资源).

The server needs to perform a query on your behalf, so if there are no individual documents being read on the server, it charges you for the query (actually reading the index) to prevent constant detach/reattaches (which use up server resources).

这真的很有意义.

我认为您必须明确删除它,然后根据文档重新初始化所有内容.

I think you have to remove it explicitly and reinitialize everything according to the doc.

是的,这是正确的.当不再需要该侦听器时,只需将其分离即可.

Yes, that's correct. When the listener is no more needed, simply detach it.

因此,我可以显式调用remove并重新初始化快照侦听器以获取更改,但是这样做会产生一定的代价吗?

So I can explicitly call remove and reinitialize the snapshot listener to get changes, but is there a price penalty for doing this?

您始终需要为阅读的文档数付费.例如,如果查询返回两个文档,则将向您收取两次文档读取费用.如果没有结果,则只需要执行一次读取操作即可计费.

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分钟之内读取缓存的值不会花费任何费用,那么这是否意味着连接和分离快照侦听器也不会花费任何费用?

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 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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