diff options
author | Sean McGivern <sean@gitlab.com> | 2017-05-31 18:45:14 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-06-01 12:21:26 +0300 |
commit | 7f73f440f9a4a8761c083a6781d3c4015228d9b9 (patch) | |
tree | 8119689770dfa79aaf1e77fc7c6d06a7b8b6cca2 /app/models | |
parent | 228926daee799c95e752a3c284c860e5bc60e528 (diff) |
Fix N+1 queries for non-members in comment threads
When getting the max member access for a group of users, we stored the results
in RequestStore. However, this will only return results for project members, so
anyone who wasn't a member of the project would be checked once at the start,
and then once for each comment they made. These queries are generally quite
fast, but no query is faster!
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project_team.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 543b9b293e0..e1cc56551ba 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -167,7 +167,7 @@ class ProjectTeam access = RequestStore.store[key] end - # Lookup only the IDs we need + # Look up only the IDs we need user_ids = user_ids - access.keys return access if user_ids.empty? @@ -178,6 +178,13 @@ class ProjectTeam maximum(:access_level) access.merge!(users_access) + + missing_user_ids = user_ids - users_access.keys + + missing_user_ids.each do |user_id| + access[user_id] = Gitlab::Access::NO_ACCESS + end + access end |