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,9 +391,12 @@ class User < ActiveRecord::Base ...@@ -391,9 +391,12 @@ class User < ActiveRecord::Base
# Groups user has access to # Groups user has access to
def authorized_groups def authorized_groups
@authorized_groups ||= begin @authorized_groups ||=
group_ids = (groups.pluck(:id) + authorized_projects.pluck(:namespace_id)) begin
Group.where(id: group_ids) union = Gitlab::SQL::Union.
new([groups.select(:id), authorized_projects.select(:namespace_id)])
Group.where("id IN (#{union.to_sql})")
end end
end end
......
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