gpt4 book ai didi

Firebase Firestore。 "Cost"onSnapshot

转载 作者:搜寻专家 更新时间:2023-10-30 22:42:28 25 4
gpt4 key购买 nike

我需要在页面上放置一个大约 20 个 Vue 组件。每个组件在挂载时都会为自己创建一个 onSnapshot,相应地,当它被删除时会创建一个 unsubscribe()

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

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

每次onSnapshot/unsubscribe 的成本是多少:

  1. 在执行时间的意义上
  2. 在金钱意义上(根据 Firebase 的价格)

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

也许在整个 collection 组件上制作 onSnapshot 会更好?

最佳答案

Firestore documentation中找到您需要的信息

Listening to query results

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.)

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

因此,每次更新集合中的记录时,所有订阅的用户都会执行一次读取。您应该花时间估算您将拥有的活跃用户数量以及数据的数量/频率,这将有助于采用适合您的应用的最便宜和最好的解决方案。

我还添加了默认的 Firebase pricing calculator它位于页面底部,一定会帮助您做出决定。

关于Firebase Firestore。 "Cost"onSnapshot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51429365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com