Firebase Firestore.“费用"onSnapshot [英] Firebase Firestore. "Cost" onSnapshot

查看:34
本文介绍了Firebase Firestore.“费用"onSnapshot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在页面上放置大约20个Vue组件.每个组件在安装后都会为其自身创建一个 onSnapshot ,并在删除后创建一个 unsubscribe().

I need to place an approximately 20 Vue component on the page. Each component, when mounted, creates an onSnapshot for itself and, accordingly, unsubscribe() when it is deleted.

const ref = firebase.firestore().collection('components').doc('comp1')

var unsubscribe = ref.onSnapshot(querySnapshot => {
  querySnapshot.forEach(doc => {
     ...
  })
}

每个 onSnapshot /退订的成本是多少:

  1. 从执行时间的角度来看
  2. 从金钱的角度(根据Firebase的价格)

例如,如果每1000个用户在半小时内将一个包含20个组件的页面更新100次,我将支付多少费用?

How much will I pay, for example, if each of 1000 users update a page with 20 components 100 times in half an hour?

也许最好对整个组件的 collection 进行 onSnapshot ?

Perhaps it would be better to make onSnapshot on the whole collection of components?

推荐答案

Firestore文档

收听查询结果

Cloud Firestore允许您侦听查询结果并在查询结果更改时获取实时更新.

Cloud Firestore allows you to listen to the results of a query and get realtime updates when the query results change.

当您侦听查询结果时,每次在结果集中添加或更新文档时,您都要付费.当文档从结果集中删除时,由于文档已更改,您还需要为阅读付费.(相反,删除文档后,您无需支付阅读费用.)

When you listen to the results of a query, you are charged for a read each time a document in the result set is added or updated. You are also charged for a read when a document is removed from the result set because the document has changed. (In contrast, when a document is deleted, you are not charged for a read.)

此外,如果侦听器断开了30分钟以上的连接(例如,如果用户离线),则将向您收取读取费用,就好像您发出了全新的查询一样

Also, if the listener is disconnected for more than 30 minutes (for example, if the user goes offline), you will be charged for reads as if you had issued a brand-new query

因此,每当您更新集合中的记录时,所有受限制的用户都将执行读取.您应该花些时间估算即将拥有的活跃用户数量以及数据数量/频率,这将有助于选择最适合您应用的最便宜和最佳解决方案.

So every time you update a record in your collection, all the suscribed users will perform a read. You should take your time in estimating the amount of active users you are going to have and the amount/frequency of your data, that will help in taking the cheapest and best solution that suits for your app.

我还要在页面底部添加默认的 Firebase定价计算器肯定会帮助您做出决定.

I'm also adding the default Firebase pricing calculator which is at the bottom at the page and will definitely help you to take a decision.

这篇关于Firebase Firestore.“费用"onSnapshot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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