From the articles I've read about keeping "references" in Firebase (1, 2, 3), I've failed to understand which would be the best way to reference other objects, if we need to listen to all the referenced object's attributes.
Data:
I have users, that can get into the role of a player, when they join a tournament:
"t_3515":{
"entry_fee":100,
"status":"Cancelled",
"players":{
"p_3":{
"player_name":"User A",
"score":"0",
"status":"Waiting"
},
"p_4":{
"player_name":"User B",
"score":"0",
"status":"Accepted"
}
}
}
I have a list with all the system's tournaments.
How I have to show this data:
- One screen that shows/listens "all" the list of tournaments.
- One screen with shows/listens the tournaments that the logged user belongs to.
I'm looking for the best way (in terms of performance) to structure the data for both requirements.
Possible solution 1:
Duplicate each tournament for each player, which means:
- accessing an user's tournaments with firebaseURL//tournaments, making it easy for a client to display it in a list. (good!)
- each whole tournament will be copied in each player's URL. (bad?)
Possible solution 2:
Follow this approach, which means:
- to access the user's tournaments, client should subscribe to firebaseURL//tournaments (to know when a tournament is added/removed), then iterate over each tournament, look for its original data's URL, and subscribe to it. (horrible)
- The tournament's data will be kept in one place only. (good)
Theoretically, this app will have thousands of tournaments and users, which I guess is something to keep in mind if we end up duplicating the data like in solution 1.