Tuesday, 7 May 2019

Firebase is getting laggy if react-native debugger is not open

I have a basic chat app which contains only conversations and messages. A user can send a message and other one receives it. It's working good on simulator but when I upload my app to my device (iPhone SE) it's getting laggy.

I've found something, if remote debugger is open app is working very smoothly, otherwise it's starting to work like second video.

How is that problem related to react-native remote debugger?

What I've done?

I tried to configure offline data and I managed to setup. But it didn't make any difference.

Videos

My app on the simulator My app on my device

Send message code

const msg = {
    name,
    text,
    createdAt: firebase.firestore.FieldValue.serverTimestamp(),
    senderId,
    receiverId,
  };
  const conversationId = createOneToOneMessageId(senderId, receiverId);
  const rootRef = firebase.firestore();
  const batch = rootRef.batch();

  const newMessageRef = rootRef
    .collection('conversations')
    .doc(conversationId)
    .collection('messages')
    .doc();

  batch.set(newMessageRef, msg);

  const updateSenderConversationRef = rootRef
    .collection('user-conversations')
    .doc(senderId)
    .collection('conversations')
    .doc(conversationId);

  batch.update(updateSenderConversationRef, {
    lastMessage: msg.text,
    lastMessageDate: msg.createdAt,
  });

  const updateReceiverConversationRef = rootRef
    .collection('user-conversations')
    .doc(receiverId)
    .collection('conversations')
    .doc(conversationId);

  batch.update(updateReceiverConversationRef, {
    lastMessage: msg.text,
    lastMessageDate: msg.createdAt,
  });

  batch.commit();

Question

  • Is that "latency" happens because of batch write operation?
  • Is there a difference between my device and the simulator for cloud firestore?
  • And obviously, how can I solve this problem?


from Firebase is getting laggy if react-native debugger is not open

No comments:

Post a Comment