firebase负责从firestore js sdk缓存中检索文档 [英] does firebase charge for retrieving docs from firestore js sdk cache

查看:51
本文介绍了firebase负责从firestore js sdk缓存中检索文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我使用的是Firebase JS SDK,具有离线持久性已启用.这将自动将我检索到的文档缓存在JS SDK中.
  • 我执行以下查询:
  • I am using the firebase JS SDK, with offline persistence enabled. This will automatically cache my retrieved documents inside the JS SDK.
  • I perform this query:
// once
firebase.firestore().doc('path/to/doc').get()
// twice
firebase.firestore().doc('path/to/doc').get()

我的问题是:

  1. 在启用离线持久性的情况下,Firebase会向我收取两次读取费用.因为我相信第二读将来自脱机缓存而不进行网络调用?
  2. 禁用离线持久性后,Firebase会向我收取一次 还是两次?
  1. Would Firebase charge me for two reads in the case offline persistence is enabled. Since I believe the second read would come from the offline cache without making a network call?
  2. Would Firebase charge me once or twice when offline persistence is disabled?

我的用例

用户从客户端打开带有其任务"的网络应用.
每个任务都有一个带有文档参考的client字段.

My use case

A user opens a web-app with his 'tasks' from clients.
Each task has a client field with a document reference.

  1. 检索所有任务(例如500次读取)
  2. 检索每个任务的每个客户端文档(即使某些客户端相同,也会读取500个文档)

所以如果只说20个客户端,我宁愿只有520个读取,而不是用户打开应用程序时的1000个读取.

So if there are only say 20 clients, I'd rather have only 520 reads instead of 1000 reads when the user opens the app.

是否最好重新设计数据结构,以便将相关的客户信息保存在任务本身上而不是引用上,否则Firebase JS SDK是否足够聪明以至于不会重复检索刚刚检索的同一文档.

Is it better to redesign my data structure to have the relevant client information saved on the task itself instead of a reference, or will the Firebase JS SDK be smart enough to not double retrieve the same doc it just retrieved.

PS:我在这里发现了类似的问题:

PS: I found a similar question here:

Firestore收费云功能是否对检索到的内容进行读取文件?

但是它没有我想要的确切信息.

But it just didn't have the exact information I was looking for.

推荐答案

从Firestore JS SDK缓存中检索文档需要Firebase收费吗?

does firebase charge for retrieving docs from firestore js sdk cache?

不,不是.如果从本地缓存中完成读取,则不会将其计为服务器端读取.

No it doesn't. If a read is fulfilled from the local cache, it is not charged as a server-side read.

但是您的代码有两个get调用:

But your code has two get calls:

// once
firebase.firestore().doc('path/to/doc').get()
// twice
firebase.firestore().doc('path/to/doc').get()

在这种情况下,Firestore客户端无法知道在这两个调用之间是否更改了文档.因此,它必须调用服务器以确定文档是否已更改,该文档是(或至少是 )收费记录.

And in this case, the Firestore client has no way to know whether the document was changed between these two calls. So it has to call to the server to determine whether the document was changed, which is (or at least may be) a charged read.

如果您需要了解应用程序中多个位置的文档的当前状态,这些位置会相互靠近(在时间上执行),则应在该文档上保留一个onSnapshot侦听器.这样可以确保本地缓存始终保持最新状态,并且成本最低.

If you need to know the current state of a document in multiple places in your app that execute close to each other (time wise), you should keep an onSnapshot listener on that document. This ensures that the local cache is always up to date at a minimal cost.

这篇关于firebase负责从firestore js sdk缓存中检索文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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