-
Notifications
You must be signed in to change notification settings - Fork 3
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
User as stored in a seat is duplicated and can go out of sync #370
Comments
Makes sense, and it sounds like this would fix the "deleting user leaves user in games issue"
There is actually a reason I went this way, instead of querying the user table. Load is theoretically faster if all the data lives in a single document/collection. See Improve Your Schema: Reduce
If performance were critical, I'd say we need to optimize for game load over user edits. However, the performance gains are difficult to see at our scale, and the benefit w.r.t. keeping data in sync without additional code is probably worth the tradeoff. |
Oh hm, if it's intended, please feel free to close this issue. I'm still trying to wrap my head around how relations can / should work in MongoDB. |
It's fine for us to change the intended behavior, especially if it's perceived as a bug 😅 I just wanted to provide some context on why it was originally implemented this way.
I think the strength of "non-relational" databases like Mongo is exactly that relations are not necessary at all. But we can take a balanced approach if the use-case requires it. |
When a user takes a seat, the whole user document is copied into the game document. So the data is (unnecessarily) duplicated, which makes it possible to go out of sync (e.g. when the rating updates).
This can be reproduced by taking a seat, then finishing a game -> the user in the game document still has the old rating (observable in network tab).
A proposal to fix this is to only store the user id in the game document. Then we can maybe use lookup to join the two documents: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/
The text was updated successfully, but these errors were encountered: