In my Firebase I have the idea of users and friends.
I am unsure what the best solution to storing and retrieving friends against a user is.
Currently, I have a users node which each user is stored with a unique id from social auth.
After reading about storing data and not to nest data I have come up with this so far. Each user has a 'friends' node which contains the unique id of another user (see below)
"users" : {
"facebook:10207817038895574" : {
"appearOffline" : false,
"avatar" : "https://scontent.xx.fbcdn.net/hprofile-xap1/v/t1.0-1/p100x100/10314019_10207798442030664_281467953303549494_n.jpg?oh=ac439386757bf533b56a7ea92022e304&oe=57732581",
"email" : "chris-barnett@live.co.uk",
"friends" : {
"google:110510990218136599589" : true
},
"id" : "facebook:10207817038895574",
"lastActive" : "2016-04-18T15:11:16.463Z",
"location" : {
"lastUpdate" : "",
"lat" : 0,
"lng" : 0
},
"name" : "Chris Barnett",
"status" : "Offline"
},
"google:110510990218136599589" : {
"appearOffline" : false,
"avatar" : "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",
"email" : "app.hub.cb@gmail.com",
"friends" : {
"facebook:10207817038895574" : true
},
"id" : "google:110510990218136599589",
"lastActive" : "2016-04-18T14:48:23.238Z",
"location" : {
"lastUpdate" : "",
"lat" : 0,
"lng" : 0
},
"name" : "Hub App",
"sentFriendRequests" : {
"twitter:95970727" : false
},
"status" : "Offline"
},
"twitter:95970727" : {
"appearOffline" : false,
"avatar" : "https://pbs.twimg.com/profile_images/692823737683578883/RxMpiuco_normal.jpg",
"email" : "-",
"id" : "twitter:95970727",
"lastActive" : "2016-04-18T14:30:40.160Z",
"location" : {
"lastUpdate" : "",
"lat" : 0,
"lng" : 0
},
"name" : "Chris Barnett",
"receivedFriendRequests" : {
"google:110510990218136599589" : false
},
"status" : "Offline"
}
}
What is the best approach for displaying all data for each friend for a user? Currently I would have to download the entire users node and do a check to see if each users unique id is in a users list of 'friends' and if it is then display their data in my view. I guess this would be ok for a small amount of users but if this was to scale then I imagine it would be very inefficient?
I am using the JavaScript SDK.
Many thanks.