Firestore:使用引用读取数据是否增加了请求数量? [英] Firestore: Reading data with references do increase in number of requests?

查看:35
本文介绍了Firestore:使用引用读取数据是否增加了请求数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

读取firestore上的文档时,firestore不会提供引用数据(如果有).所以目前我正在要求Firestore从参考路径中获取数据.这是否增加了对服务器的请求数量,从而最终降低了性能并提高了定价?在从服务器请求数据方面,存储引用有何帮助?

When documents on firestore is read, firestore wont give references data, if any. so currently I am requesting firestore for data from reference path. Do this increase in number of requests to server, eventually decrease in performance and increase in pricing ? How storing references is helpful in terms of requesting data from server ?

推荐答案

读取具有引用的文档将视为对该文档的读取.读取引用的文档将作为对另一文档的读取.因此,总共是两次读取.

Reading a document that has a reference counts as a read of that document. Reading the referenced document count as a read of another document. So in total that is two reads.

这里没有隐藏的通货膨胀:如果服务器要自动遵循参考,则还必须阅读两个文档.

There is no hidden cost-inflation here: if the server were to automatically follow the reference, it would also have to read both documents.

如果您希望最大程度地减少阅读的文档数量,可以考虑将所需的最少数据从引用文档添加到包含引用的文档中.例如,如果您有一个聊天应用程序:

If you're looking to minimize the number of documents you read, you can consider adding the minimum data you need from the referenced document into the document containing the reference. For example, if you have a chat app:

  • 您可能希望在消息本身中包括每个发布消息的用户的显示名称,这样您就不必阅读用户的个人资料文件.
  • 如果这样做,则必须考虑如果用户更新其显示名称该怎么办.有关某些选项,请参见我的回答:如何在Firebase中写入非规范化数据
  • 用户数量可能少于聊天消息的数量(并且在特定的时间范围内受限制),从而使链接文档的读取次数少于消息的数量.
  • 通过复制数据,您可能会夸大带宽使用量,尤其是在用户数量远低于消息数量的情况下.

这可以归结为:您可能过早地进行了优化,但是即使没有,也没有:没有一种千篇一律的方法.NoSQL数据建模取决于应用程序的用例,Firestore也不例外.

What this boils down to is: you're likely optimizing prematurely, but even if not: there's no one-size-fits-all approach. NoSQL data modeling depends on the use-cases of your app, and Firestore is no different.

这篇关于Firestore:使用引用读取数据是否增加了请求数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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