Why is it consuming much time to retrieve data from firestore with flutter?

与世无争的帅哥 提交于 2020-01-07 08:21:23

问题


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 Above codes taking approx 10 min to retrieve data from firestore, Why is it too lazy?


回答1:


It got solved by testing it on another device and running smoothly without any much time consumption. Actually my first device's memory has filled, so that's why, taking too much time.

But I'm still confuse, what the relation between device's memory space and firestorm database..!




回答2:


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).

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.

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



来源:https://stackoverflow.com/questions/58935132/why-is-it-consuming-much-time-to-retrieve-data-from-firestore-with-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!