简体   繁体   English

Flutter Firestore具有相同文档的两个StreamBuilder计为2次读取?

[英]Flutter Firestore Two StreamBuilders of the Same Document Count as 2 Reads?

In my Flutter app, will it count as two reads from Firestore if I have two nested StreamBuilders reading from the same document? 在我的Flutter应用中,如果我有两个嵌套的StreamBuilders从同一个文档中读取,那么它将算作Firestore的两次读取? Or is it cached in a way that it will only count as one read? 还是以仅将其视为一次读取的方式进行缓存?

Here's an example of what I'm talking about. 这是我正在谈论的示例。

StreamBuilder(
  stream: Firestore.instance.document(path).snapshots(),
  builder: (context, asnap){
    //Some nested widgets...
    return StreamBuilder(
      stream: Firestore.instance.document(path).snapshots(),
      builder: (context, asnap){
        return MyWidget();
      },
    );
  },
);

As far as I know, the Firestore client deduplicates these listeners. 据我所知,Firestore客户端对这些侦听器进行了重复数据删除。 So if a first listener is already active for the exact same data, it won't attach a second listener. 因此,如果第一个侦听器已经对完全相同的数据处于活动状态,则不会附加第二个侦听器。 So you won't be charged for two reads, but (possibly even more important to your users) the data will only be transferred once. 因此,您无需为两次读取支付费用,但是(对于您的用户而言可能更为重要)数据只会被传输一次。

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

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