简体   繁体   English

如何更新文档而不导致写入 Firestore?

[英]How to update a document without causing a write firestore?

I am building a billing web app where users update stock of an item frequently.我正在构建一个计费 web 应用程序,用户在其中经常更新物品的库存。 So it will cost me much.所以我会花很多钱。 Is there a way to only update the stock without causing a document write?有没有办法只更新库存而不导致文件写入?

Short answer: no简短的回答:没有

Long answer: most likely not长答案:很可能不是

Each document updated will count as a document write for billing on Firestore.每个更新的文档都将计为在 Firestore 上计费的文档写入。 Even if you try to bundle multiple updates into a single batch call.即使您尝试将多个更新捆绑到一个批处理调用中。

One suggestion would be to throttle updates on the client side to slow down rapid updates.一种建议是在客户端限制更新以减慢快速更新的速度。 This will however affect the accuracy of the data your end users will get while using the app.但是,这会影响最终用户在使用应用程序时获得的数据的准确性。 Example of throttling: Small article on throtting/debouncing节流示例: 关于节流/去抖动的小文章

Another suggestion is to avoid making updates that are meaningless.另一个建议是避免进行无意义的更新。

You can check if a value isn't going to change or if the value change isn't important before trying to do an update:您可以在尝试进行更新之前检查值是否不会更改或者值更改是否不重要:

function updateValue(newValue) {
    // Check if value has changed
    if (newValue === value) {
        // pass
        return;
    }

    // make an update request
    // ...
}

Any other suggested solution would require your end users sharing the same network or introducing another service outside of Firestore.任何其他建议的解决方案都需要您的最终用户共享同一网络或在 Firestore 之外引入其他服务。

Last thing to consider is that maybe it's too soon to consider billing.最后要考虑的是,考虑计费可能为时过早。 Firestore is pretty cheap for what it offers. Firestore 的价格相当便宜。 Here's a good video by Firebase about billing:这是 Firebase 关于计费的精彩视频:

Firebase video on Getting to know pricing Firebase 视频了解定价

If none of these suggestions has been helpful, I'd recommend adding some code examples, etc for better suggestions:)如果这些建议都没有帮助,我建议添加一些代码示例等以获得更好的建议:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM