This is a group chat app using Firebase. I have few data schema option and I don't know what would be better for performance and less data usage.
Let's suppose there are 10 rooms. this rooms is already made.
Each room's id is [A, B, C, D, E, F, G, H, I, J]
Option 1
/users
- /$uid/joined
- room1 { roomId : A }
- /$uid/joined
/rooms
- room1 { roomId: A, users : [ ... ] }
/messages
- room1 { roomId: A, messages : [ ... ] }
Option 2
/users
- /$uid/joined
- room1 { roomId : A, lastChecked, joinedAt... }
- /$uid/joined
/rooms
- room1 { roomId : A, users : [], messages : [] }
Which is better? First time I planned to use Option 1. For decreasing data usage, I want to handle room's brief information and messages separately. But during of developing, I realized the firebase's database is handled by specific keys...
For example, when user access to a room,
Update his/her joined room information at
/users/$uid/joined, uid needed.Update room's joined users at
/rooms/$roomKey/users, roomKey needed, and I have to query it using room's Id(A)After access room, Get messages at
/rooms/$key/messagesand its key is different with above$roomKey.
Above is option 1's scenario, and If I use option 2, I don't need to get messages again in different path. But the reason of why I ask of this question, Then how about rendering "The list of joined rooms" screen? each room should has a brief information such as title, the number of users, the count of unread messages. If I put messages to /rooms, the messages will queried together. right?
I think the messages is the biggest data size. How can I make this data structure?
