Home > OS >  is Firestore listen method effect performance app
is Firestore listen method effect performance app

Time:12-04

my question is very simple but it mean a lot to me , i have more than 4 listen method in my flutter app which i can't use .cancle() to them since they are so important to keep in listen as long as user is active ,

Now my question is : let's say the app has thousands of active users monthly .. does it will effect of response performance of Firestore with these 4 listens methods for thousands of monthly active users ?

my listens methods are similar like this kind of data size .. most of them are moving data FROM/TO another collection's

FirebaseFirestore.instance.collection("users").doc(currentUser.uid).collection("handleCountM").where("new", isEqualTo: true).snapshots();
   .listen((value){
  value.docs.forEach((val) async {
    String textMessage = await  val.get("textMessage");
    String image1 = await  val.get("image1");
    var timestamp = await val.get("timestamp");
    String messageTime = await val.get("messageTime");
    String name = await val.get("name");
    String bio = await val.get("bio");
    String senderUid = await val.get("senderUid");
    String receiverUid = await val.get("receiverUid");
    String notificationId = await val.get("notificationId");



    final DocumentSnapshot countM2Id = await  FirebaseFirestore.instance.collection("users").doc(currentUser.uid).collection("messages").doc(val.id).get();

    if(countM2Id.exists  ) {
      int countM2 = await countM2Id.get("countM2");

      final QuerySnapshot<Map<String, dynamic>> lengthId = await FirebaseFirestore.instance.collection("users").doc(currentUser.uid).collection("chats1").doc(val.id currentUser.uid).collection("chats2").get();

      await FirebaseFirestore.instance.collection("users").doc(currentUser.uid).collection("messages").doc(val.get("senderUid")).update({
        "textMessage":  textMessage,
        "image1": image1,
        "timestamp": timestamp,
        "messageTime": messageTime,
        "name": name,
        "bio": bio,
        "senderUid": senderUid,
        "receiverUid": receiverUid,
        "countM2":  countM2,
        "countM":  lengthId.docs.length - countM2,
        "notificationId":  notificationId,


      });

also i have read in firestore docs best performance section that should put under 100 listen snapshot methods fo each user . does it mean in my case no worries ? or they mean something is difference of my understanding .

thanks in advance

CodePudding user response:

You're probably safe. It's really hard to have low performance on Firestore.

As far as I know, when it comes to performance and even costs the you only thing you need to worry is about how much data you're getting each time. It's easier to have performance issues with network (when you grab too much data in one time) so don't make your documents too big and don't grab too many documents at once that you may not need.

Also, setting up some listeners per user isn't a big deal either. Just be aware about how often you'll get charged for new reads when they are active if the data they're listening changes too often.

For instance, if the data on those collections are changing several times and you have thousands of users listening to the same collection queries, you may be charged for a lot of new reads every time there's a new value.

  • Related