summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-11-12 17:38:20 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-11-18 13:05:45 +0100
commit189c40c33d18df08dd40e9f009f6658f89e3af0e (patch)
treeae26e92936bc9ed6e2e4755b5287dabe5168b93e /app/models/user.rb
parent656d9ff69b372be8e0aebb94418c487e76e04256 (diff)
downloadgitlab-ce-189c40c33d18df08dd40e9f009f6658f89e3af0e.tar.gz
Use SQL::Union for User#authorized_groups
This removes the need for plucking any IDs into Ruby.
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 8f34f52be1d..ddb3158e0f5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -391,10 +391,13 @@ class User < ActiveRecord::Base
# Groups user has access to
def authorized_groups
- @authorized_groups ||= begin
- group_ids = (groups.pluck(:id) + authorized_projects.pluck(:namespace_id))
- Group.where(id: group_ids)
- end
+ @authorized_groups ||=
+ begin
+ union = Gitlab::SQL::Union.
+ new([groups.select(:id), authorized_projects.select(:namespace_id)])
+
+ Group.where("id IN (#{union.to_sql})")
+ end
end
# Projects user has access to