diff options
author | Nick Thomas <nick@gitlab.com> | 2017-08-11 15:19:11 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-08-14 12:47:15 +0100 |
commit | d7b03c37f8346e29f21f0196fd3a532effa60ec3 (patch) | |
tree | dae0a75f4dd508f2531788247d8bac88e0484162 /app/models/group.rb | |
parent | 455dc74e65e7461c1a51bf3ea6594fe20b9df90c (diff) | |
download | gitlab-ce-d7b03c37f8346e29f21f0196fd3a532effa60ec3.tar.gz |
Speed up Group#user_ids_for_project_authorizations
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index bd5735ed82e..2816a68257c 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -212,21 +212,39 @@ class Group < Namespace end def user_ids_for_project_authorizations - users_with_parents.pluck(:id) + members_with_parents.pluck(:user_id) end def members_with_parents - GroupMember.active.where(source_id: ancestors.pluck(:id).push(id)).where.not(user_id: nil) + # Avoids an unnecessary SELECT when the group has no parents + source_ids = + if parent_id + self_and_ancestors.reorder(nil).select(:id) + else + id + end + + GroupMember + .active_without_invites + .where(source_id: source_ids) + end + + def members_with_descendants + GroupMember + .active_without_invites + .where(source_id: self_and_descendants.reorder(nil).select(:id)) end def users_with_parents - User.where(id: members_with_parents.select(:user_id)) + User + .where(id: members_with_parents.select(:user_id)) + .reorder(nil) end def users_with_descendants - members_with_descendants = GroupMember.non_request.where(source_id: descendants.pluck(:id).push(id)) - - User.where(id: members_with_descendants.select(:user_id)) + User + .where(id: members_with_descendants.select(:user_id)) + .reorder(nil) end def max_member_access_for_user(user) |