Monday, 1 February 2021

How firebase real time database reads data?

I am working on a chat app where messages store in firebase realtime database. Now if i make a node shown below ( chats-Between-A-and-B-Id are autogenerated chatroom keys ), so i want to know that when user S open chats with user T in chat app so Database will read only the messages stored in chats-Between-S-and-T-Id and will not read others chatroom messages !? am i right ? if yes then will it reduce the pricing?

chats-
      chats-Between-A-and-B-Id-
                 messageID1-…
                 messageID2-…
                 messageID3-…
                 ...
      chats-Between-o-and-p-Id-…
      chats-Between-s-and-t-Id-…
      chats-Between-x-and-y-Id-…

OR

If i store data like shown below then if user S open chats of user T in chat app so Database will read whole messages and

cahts-
      messageID1-…
      messageID2-…
      messageID3-…
      ...

sort them like (shown below) so it will read all messages and sort them and show in app to the user !? which will increase the pricing ?

if(chat.getReceiver() == senderID && chat.getSender() == receiverId ||
   chat.getReceiver() == receiverId && chat.getSender() == senderID)
                          {
                             (mChatList as ArrayList<Chat>).add(chat) //show chats
                          }

I want to know which approach can save my money.



from How firebase real time database reads data?

No comments:

Post a Comment