I'm trying to find the best method for storing and retrieving a list of posts with comments in Firebase using the RTDB (not Firestore as this project has been ongoing for a while).
I have a set of users:
And I have a set of posts
Some people have suggested storing the user's name directly in the post and post comments, but I am nervous that at some point they will change their information. Plus, I'd like additional info (reputation, member since, etc.) to show up.
My thought is querying for each user and storing the object in an associative array. So the first time UID 1234 comes up, the code will check the array, and if it doesn't exist, it will query it from the database.
users = {};
getUser( uid ){
return new Promise( (resolve, reject ) =>{
if( this.users && this.users[ uid ] ){
resolve( this.users[ uid ] );
} else {
this.angular.object('users/'+uid ).snapshotChanges().take(1).subscribe( data =>{
const user = data.payload.val();
if( user ){
this.users[ uid ] = user;
resolve( user );
} else {
reject();
}
});
}
});
}
If 100 users and comments are on a page, I am wondering if that will be inefficient? And is that too many queries for something like Firebase to handle?