为什么要花很多时间从扑朔迷离的Firestore中检索数据? [英] Why is it consuming much time to retrieve data from firestore with flutter?

查看:70
本文介绍了为什么要花很多时间从扑朔迷离的Firestore中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我添加了一个动画,动画完成后,我在代码行下面调用了它,但它消耗了太多时间。

first,I added an animation, after animation completed I called below code line but it's consuming too much time.

getData()async{
 DateTime now = DateTime.now();
       await Firestore.instance.collection('Table_Name').getDocuments().then((QuerySnapshot snapshot){

        print("length ${snapshot.documents.length}");
        for(int i = 0 ; i< snapshot.documents.length; i++){

          bool isToday = snapshot.documents[i].data['CreatedBy'].toString().split(" ")[0]==DateFormat("yyyy-MM-dd").format(now);
          print("isTOday $isToday");
          if(isToday && snapshot.documents[i].data['GainStatus']== "0"){
            setState(() {
            giftDocumentID = snapshot.documents[i].documentID; 
            });
            break;
          }
        }
        winOrLose(now);
        print("giftDocumentID: $giftDocumentID");
      });
}

This以上代码大约需要10分钟才能从firestore中检索数据,为什么

This Above codes taking approx 10 min to retrieve data from firestore, Why is it too lazy?

推荐答案

firestore数据和设备内存之间的关系是缓存。首次加载数据时,数据是从firebase的服务器加载的(因此会增加您读取请求的费用),然后firestore将数据保存在缓存中以备将来使用。因此,缓慢地检索数据必定是设备操作系统问题(或电源问题)。

The relation between firestore data and device's memory is cache. When data is loaded for the first time, it's from firebase's servers (and thus costs you read requests), then firestore saves the data in the cache memory for future use. So slow retrieval of the data must be a Device OS problem (or a power issue).

您可以从Firebase数据中删除缓存功能,但我不建议这样做。

You can remove caching feature from firebase data but I won't recommend that.

同样如前所述,您不应一次加载所有数据,特别是如果要大量提取数据或经常更改数据时。

Also as suggested earlier you should not load all data at once especially if the data is going to be fetched a lot or data gets changed very often. The solution for that is pagination.

该视频很好地解释了Flutter分页:
https://www.youtube.com/watch?v=coR4Y-DkrLc

This Video explains Flutter Pagination nicely: https://www.youtube.com/watch?v=coR4Y-DkrLc

这篇关于为什么要花很多时间从扑朔迷离的Firestore中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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