firebase - 关于firestore缓存和读取费用的问题

标签 firebase google-cloud-firestore

我了解 Firestore 缓存和读取费用在这些情况下的表现。我不确定它是否正确。

如果我的集合中有 2000 个文档。此集合名称为“testCollection”。这些文档不会更改、更新或删除。 我的客户端是android,已经启用离线持久性并且设备当前在线

1.

db.collection("testCollection").onSnapshot(function(doc) {});

2000 次阅读已收费 这些文档被缓存。 然后重新打开应用程序并再次运行相同的代码

db.collection("testCollection").onSnapshot(function(doc) {});

另外 2000 次读取被收费,因为 firestore 需要检查每个文档是否是最新的。 所以2000+2000次读取要收费

2.

我不确定这是如何表现的。 只需一起运行相同的代码

db.collection("testCollection").onSnapshot(function(doc) {}); 
db.collection("testCollection").onSnapshot(function(doc) {});

我认为 2000 次读取要收费,因为数据保持最新

3.

db.collection("testCollection").limit(300).onSnapshot(function(doc) {}); 
db.collection("testCollection").limit(800).onSnapshot(function(doc) {}); 

总共 1100 次读取被收费。因为这是不同的查询。

我是不是有什么误解或者错误?

最佳答案

2000 reads charged and those documents are cached.

这是正确的,因为这是您第一次执行这些读取操作。

another 2000 reads charged cause Firestore needs to check each document is up to date or not. So 2000+2000 reads charged

一旦文档位于缓存中并且这些文档没有更改(如您所说),所有读取操作都来自缓存。您无需为来自缓存的读取操作付费。

I think is 2000 reads charged because data is keeping up to date

仅当 Firebase 服务器上的数据发生更改时,您才需要为其他读取操作付费,否则,您将从缓存中获取数据。

Total 1100 reads charged.cause it's a different query

如果您已经执行了初始查询并且已经获得了这 2000 个文档,那么如果您执行另一个查询,无论是否使用限制,您都会从缓存中读取所有这些文档。

关于firebase - 关于firestore缓存和读取费用的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56617814/

相关文章:

javascript - Firebase - Cloud Firestore 触发器幂等性

firebase - flutter应用程序无法与Firebase云数据库进行交互

java - Firestore Recycler 未在应用屏幕上显示任何结果且没有错误

javascript - 从文档顺序中获取第一个 Firestore 文档 (Node.js)

javascript - array_contains 对象查询

javascript - 如何将 Canvas 作为图像保存到 Firebase 存储?

angularjs - 离线 Firebase

firebase - 获取 Firebase Storage 文件夹中使用的存储空间

firebase - Firebase存储REST API

javascript - 使用 Firestore,您可以使用单个更新调用更新和添加到子集合吗?