diff options
author | Stan Hu <stanhu@gmail.com> | 2016-06-28 09:02:27 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-06-29 03:12:57 -0700 |
commit | e21c7d37c8cd21be1489f6dd445d5efa24e94456 (patch) | |
tree | c89ab8603436945ecc62b45f2dd3dd3b51423cd8 /app/models/project_team.rb | |
parent | 1023289605f075cef86833ab5c1b0e87d967f69e (diff) | |
download | gitlab-ce-e21c7d37c8cd21be1489f6dd445d5efa24e94456.tar.gz |
Reduce overhead and optimize ProjectTeam#max_member_access performance
The previous implementation would load the entire team member list and their
respective attributes. Now we only search for the user's specific
access level.
In gitlab-com/operations#42, this reduces the overall overhead of rendering
the issue from 28% to 20%.
First step of optimizing #19273
Diffstat (limited to 'app/models/project_team.rb')
-rw-r--r-- | app/models/project_team.rb | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 73e736820af..0865b979ce0 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -137,20 +137,10 @@ class ProjectTeam def max_member_access(user_id) access = [] - project.members.non_request.each do |member| - if member.user_id == user_id - access << member.access_field if member.access_field - break - end - end + access += project.members.non_request.where(user_id: user_id).has_access.pluck(:access_level) if group - group.members.non_request.each do |member| - if member.user_id == user_id - access << member.access_field if member.access_field - break - end - end + access += group.members.non_request.where(user_id: user_id).has_access.pluck(:access_level) end if project.invited_groups.any? && project.allowed_to_share_with_group? |