This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Fix db load on usersCommunities table #3826
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status
Deploy after merge (delete what needn't be deployed)
Run database migrations (delete if no migration was added)
YES
Every time anybody loaded the community view we would run a query that would go through all the members of a community (that was quick), then filter them by e.g.
isMember = true(that was slow for big communities) and then order them byr.desc('reputation'). (that was also slow)Together, the filter and the orderBy meant that we would read a couple tens of thousands of records when somebody opened a large communities community view. Multiply that by concurrent users pointed at the platform and you've got a perfect storm of traffic we can't handle.
This patch fixes it by introducing a couple new indexes on the usersCommunities table:
communityIdAndIsMembercommunityIdAndIsModerator...IsOwner...IsTeamMember(moderator or owner)Those four indexes allow us to efficiently query all the data we commonly need.