Firebase Firestore快照读取计数 [英] Firebase Firestore snapshot read count
问题描述
我正在尝试优化我的应用在Firesbase上的读取次数,并回顾我使用快照监控实时变化的方式.想象一下,我有一个快照,返回了如下的10个最新文档:
I am trying to optimize the number of reads my app makes on Firesbase and reviewing the way I use snapshot to monitor real time changes. Imagine I have a snapshot returning the 10 latest documents like the following:
db.collection("cities")
.where("state", "==", "CA").
.orderBy('dateadded', 'desc').limit(10)
.onSnapshot(function(snapshot) {
...
})
医生说
每次 查询结果更改(即添加,删除或删除文档时) 修改).
The snapshot handler will receive a new query snapshot every time the query results change (that is, when a document is added, removed, or modified).
这是否意味着每次查询更改时,我都会被收取10次读取费用?在此示例中,如果添加了新城市(因此添加了最新的"dateadded",因此在查询中排在第一位)将是1(仅是新城市)或10次读取(完整查询).
Does that mean that every time the query changes I will be billed 10 reads? In this example if a new city is added (so with the latest 'dateadded', so coming first in the query) will it be 1 (just the new city) or 10 reads (the full query).
作为一个附带的问题,在这里我可以看到我所在的确切读取次数(实时运行,因此我可以测试一个函数并查看相应的读取次数). IAM和Admin/Quota似乎在每天的读取请求"下提供了该功能,但该功能尚未生效...
As a side question where I can see the exact number of read I am at (live so I can test a function and see the corresponding number of reads). The IAM and Admin/Quota seems to provide that under "reads request per day" but it is not live...
我指的是如 https://firebase中所述的Firestore快照.google.com/docs/firestore/query-data/listen
推荐答案
如果查询结果中有1个文档发生更改,则将向您收取1次阅读的费用.您无需为未更改的文档付费.查询快照对象仅重用了先前结果集中在内存中的文档数据.
If 1 document changes in query results, you will be billed 1 read. You are not billed for documents that are unchanged. The query snapshot object merely reuses the document data that was in memory from the prior set of results.
这篇关于Firebase Firestore快照读取计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!