简体   繁体   中英

Firebase data structure for chat app

I'm looking to basically remake Kik within my app. For most guides I've seen on a firebase chat application, there is one major Messages node, and then underneath that there's a fan-out with messages for each user that reference messages in the main list.

With the way my Firebase is laid out at the moment, it would be easier to implement something like this:

users
   chatPartners
        02834092890428
           chatMessages
               2093840923840923
                   timestamp/userUID/etc.

and just have the actual chat inside of my user's node. This seems to also cut down majorly on having to sift through every single message in a messages node?

So when the users send messages to eachother, I'd update the "chat messages" node under the sender and the user.

Is there any reason NOT to do it like this? I see everyone doing it the first way I described, yet I don't see a reason why storing each chat under user--->chat partner --> the chat log would be an issue.

The only issue you may run in to is how the data is called. Note that when you call the 'Chat Log', because it is a child of 'Users' and 'chatPartners', you will be calling the data of everything in that branch, essentially loading every piece of data in the database under 'Users', which is time and performance sensitive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM