gpt4 book ai didi

firebase - 使用Cloud Firestore在Flutter中获取List 时没有读取次数

转载 作者:行者123 更新时间:2023-12-03 04:42:53 25 4
gpt4 key购买 nike

我是刚开始遇到火灾或 flutter 朔迷离的人,我想知道关于读写操作的某些事情

  • 如果在StreamBuilder中我们将DocumentSnapshots列表存储在这样的变量中,final events = snapshot.data.documents;那么读取操作的数量是否等于所有文档
    里面的收藏,还是一个?
  • 当我们使用StreamBuilder从Firestore控制台添加新文档时,是否会导致执行更多读取操作或在写入后重新构建整个Stream构建器,因此导致所有读取与以前一样加一。

  • 对不起,如果我的问题不是很清楚。
    这是我的StreamBuilder代码。
      Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
    stream: fireStore.collection('trending_events').snapshots(),
    builder: (BuildContext context, AsyncSnapshot snapshot){
    if(!snapshot.hasData){
    return CircularProgressIndicator();
    }
    if(snapshot.hasError){
    return Center(child: Text('Something Wrong'),);
    }
    final events = snapshot.data.documents;
    final urlList = [];
    for(var eventUrl in events){
    final url = eventUrl.data['video_url'];
    urlList.add(url);
    }
    return Padding(
    padding: const EdgeInsets.only(left: 10.0, right: 10.0, top: 23.0),
    child: Column(
    mainAxisSize: MainAxisSize.max,
    children: <Widget>[
    IconButton(
    icon: Icon(Icons.gesture, size: 20.0,color: Colors.black,),
    onPressed: (){
    Navigator.push(context, MaterialPageRoute(
    builder: (context) => UpcomingEvents(),
    ));
    },
    ),
    SizedBox(height: 4.0,),
    Expanded(
    child: ListVideoGenerator(listURL: urlList),
    ),
    ],
    ),
    );
    },
    );
    }```


    最佳答案

    then would the no of read operations equal to all the document inside the collection, or just one?


    如果在馆藏中有4个文件,那么您需要为这4个文件付费。

    When we add something from the firestore console using the StreamBuilder, Is only one document added resulting in one more read operation or the whole Stream builder rebuilds after taking a write, hence resulting in all the reads as before plus one.


    这将是一次读取,因为Firestore默认使用缓存。根据 docs:

    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 - 使用Cloud Firestore在Flutter中获取List <DocumentSnapshots>时没有读取次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62861532/

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