Commit 189c40c3 authored by Yorick Peterse's avatar Yorick Peterse

Use SQL::Union for User#authorized_groups

This removes the need for plucking any IDs into Ruby.
parent 656d9ff6
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment