Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why both user/totalTweets and user/stats/stats/tweets.length ? #45

Closed
stanbar opened this issue Feb 5, 2024 · 1 comment
Closed

Why both user/totalTweets and user/stats/stats/tweets.length ? #45

stanbar opened this issue Feb 5, 2024 · 1 comment

Comments

@stanbar
Copy link

stanbar commented Feb 5, 2024

Hi,
I wonder why do you use both user/totalTweets and user/stats/stats/tweets.length? What is the reason of keeping them in both places? And then when you display user's total tweets in user-header.tsx you add them together in

(user?.totalTweets ?? 0) + (tweets?.length ?? 0),
?

I also wonder why are they managed separatelly, i.e. user.totalTweets is incremented/decremented on client-side only

export async function manageTotalTweets(

While user/stats/stats/tweets is incremented/decremented on both client-side

tweets: arrayUnion(tweetId),

and only decremented on server-side via Cloud functions onDelete trigger)

export const normalizeStats = regionalFunctions.firestore

@stanbar
Copy link
Author

stanbar commented Feb 19, 2024

I figured out the answer. user/stats/stats/tweets doesn't keep track of tweets but of REtweets only. It's managed in separate doc users/{userId}/stats/stats as a optimisation, that way we don't have to fetch whole list of likes and retweets every time we want to get user doc.

I suggest renaming user/stats/stats/tweets to user/stats/stats/retweets as it is very confusing.

@stanbar stanbar closed this as completed Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant