Home > OS >  Getting user data in social apps
Getting user data in social apps

Time:09-06

I'm wondering if is possible to avoid getting user data for every content in the app.

For example;

I have a posts collection in Cloud Firestore like this: posts collection in firebase

In the app, I'm showing the last 100 posts.

Also, I'm showing the user name in the UI for each post (Using ownerID to reach the user's document).

I'm reading 200 documents from Cloud Firestore to show 100 posts in total.

And this is the User document:

enter image description here

Is there any possible way to avoid document reads in cases like this?

I tried to store the username inside of each 'post' document. But If the user changes their name or photo this data is out of date which is not desirable.

CodePudding user response:

You can use a Firebase Cloud Function to update the posts collection when a user updates their profile.

Users update their profile far fewer times than reading posts.

It is best practice to store the user data that needs to be displayed in the posts collection and update as needed.

  • Related