Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Conversation

@mxstbr
Copy link
Contributor

@mxstbr mxstbr commented Aug 23, 2018

Status

  • WIP
  • Ready for review
  • Needs testing

Deploy after merge (delete what needn't be deployed)

  • api

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 by r.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:

  • communityIdAndIsMember
  • communityIdAndIsModerator
  • ...IsOwner
  • ...IsTeamMember (moderator or owner)

Those four indexes allow us to efficiently query all the data we commonly need.

mxstbr added 2 commits August 23, 2018 10:53
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 by `r.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:

- `communityIdAndIsMember`
- `communityIdAndIsModerator`
- `...IsOwner`
- `...IsTeamMember` (moderator or owner)

Those four indexes allow us to efficiently query all the data we
commonly need.
@brianlovin brianlovin merged commit d210538 into alpha Aug 23, 2018
@brianlovin brianlovin deleted the fix-db-load branch August 23, 2018 16:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants