Issue with Firebase request – Taking more than 10 minutes randomly

I am writing several documents in my application following the acceptance of a “reservation”.
So I’m executing the following function, with a batch.
Sometimes it executes correctly, sometimes it takes more than 10 minutes to execute, on the same device, same network.

Has anyone had a similar problem? How can I solve it? Or where can I find a way to diagnose it?

Thanks in advance !

Future<void> accepterReservation() async {
    print('accepter resa');
    setState(() {
      accepterResaIsLoading = true;
    });

    ChatsRecord docChatMAJ =
        await ChatsRecord.getDocumentOnce(widget.chatDoc!.reference);

    int? prixLoc = docChatMAJ.prix;
    DateTime? dateDebut = docChatMAJ.dateDebut;
    DateTime? dateFin = docChatMAJ.dateFin;
    int daysDifference = dateFin!.difference(dateDebut!).inDays;

    if (docChatMAJ?.offrePrix != null && docChatMAJ?.offrePrix != 0) {
      setState(() {
        _model.prixCommunique = docChatMAJ?.offrePrix;
      });
      print(_model.prixCommunique);
    } else {
      print('ici');
      _model.prixCommunique = docChatMAJ?.prix;
      print(_model.prixCommunique);
    }

    String baseTextP =
        'La réservation sera validée une fois que le locataire aura réglé le montant de la location.';
    String baseTextL =
        'Effectue le paiement de ta location pour valider la réservation.';

    if (daysDifference > 6) {
      baseTextP +=
          'nLoomi ne prend pas en charge la caution pour les locations de plus de 6 jours, nous t'invitons à te rapprocher du locataire pour sa mise en place.';
      baseTextL +=
          'nLoomi ne prend pas en charge la caution pour les locations de plus de 6 jours, nous t'invitons à te rapprocher du propriétaire pour sa mise en place.';
    }

    WriteBatch batch = FirebaseFirestore.instance.batch();

    // On crée le message pour le locataire
    DocumentReference newChatMsgLoc = ChatMessagesRecord.collection.doc();
    batch.set(
      newChatMsgLoc,
      createChatMessagesRecordData(
        type: 'notification_reservation',
        destinataire: docChatMAJ.locataire,
        titre:
            'Le propriétaire a accepté ton offre de location du ${dateTimeFormat('dd/MM/y', dateDebut)} au ${dateTimeFormat('dd/MM/y', dateFin)} pour un montant de ${(fromCentimesToEuros(_model.prixCommunique)! / 1.18).toStringAsFixed(2)}€.',
        timestamp: getCurrentTimestamp,
        chat: docChatMAJ.reference,
        text: baseTextL,
      ),
    );

    // On crée le message pour le propriétaire
    DocumentReference newChatMsgProp = ChatMessagesRecord.collection.doc();
    batch.set(
      newChatMsgProp,
      createChatMessagesRecordData(
        destinataire: docChatMAJ.proprietaire,
        titre:
            'Tu as accepté la demande de location du ${dateTimeFormat('dd/MM/y', dateDebut)} au ${dateTimeFormat('dd/MM/y', dateFin)} pour un montant de ${(fromCentimesToEuros(_model.prixCommunique)! / 1.18).toStringAsFixed(2)}€.',
        text: baseTextP,
        type: 'notification_info',
        timestamp: getCurrentTimestamp,
        chat: docChatMAJ.reference,
      ),
    );

    // On mets à jour le chat
    batch.update(
      widget.chatDoc!.reference,
      {
        'lastMessage': 'Offre de location acceptée',
        'lastMessageTime': getCurrentTimestamp,
        'prix': _model.prixCommunique,
        'date_debut': dateDebut,
        'date_fin': dateFin,
        'statutLocation': 'Demande acceptée',
        'last_message_seen_by': FieldValue.arrayUnion([currentUserReference]),
      },
    );

    // Supprimer le message de demande de réservation
    batch.delete(widget.chatMessagesDoc!.reference);

    // Suppression du message permettant au locataire d'annuler sa demande
    if (widget.chatMessagesDoc!.msgAssocie != null) {
      batch.delete(widget.chatMessagesDoc!.msgAssocie!);
    }

    try {
      batch.commit();
      print('fin du batch');
    } catch (e) {
      print('Erreur lors de l'exécution du batch : $e');
    }

    print('fin du batch2');

    setState(() {
      accepterResaIsLoading = false;
      _model.lastSeenBy = [];
    });
  }

Initially, I had put an await in my code, but then all my firebase requests stopped working in my application, and it became usable.

So I removed the await, but that doesn’t solve the problem of my request taking 10 minutes for no reason. I have the same problems in several part of my application, but it’s happening randomly, I can’t find the root cause of the problem.

New contributor

Marie Dufau is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật