diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-06-10 11:26:47 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-06-13 19:32:00 -0300 |
commit | 149176758393c8d89d996c62c11511b3e86b3f8d (patch) | |
tree | 6e1a0cdc99e36278735db9beddb6899fb9aa64fe /app/models/user.rb | |
parent | b56c45675019baaaf47615d51c08d5caa0734ad3 (diff) | |
download | gitlab-ce-149176758393c8d89d996c62c11511b3e86b3f8d.tar.gz |
Use Issue.visible_to_user in Notes.search to avoid query duplication
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 69c1bf4bc3d..a5b3c8afe51 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -825,19 +825,16 @@ class User < ActiveRecord::Base private def projects_union(min_access_level = nil) - relations = if min_access_level - scope = { access_level: Gitlab::Access.values.select { |access| access >= min_access_level } } - - [personal_projects.select(:id), - groups_projects.where(members: scope).select(:id), - projects.where(members: scope).select(:id), - groups.joins(:shared_projects).where(members: scope).select(:project_id)] - else - [personal_projects.select(:id), - groups_projects.select(:id), - projects.select(:id), - groups.joins(:shared_projects).select(:project_id)] - end + relations = [personal_projects.select(:id), + groups_projects.select(:id), + projects.select(:id), + groups.joins(:shared_projects).select(:project_id)] + + + if min_access_level + scope = { access_level: Gitlab::Access.values.select { |access| access >= min_access_level } } + relations = [relations.shift] + relations.map { |relation| relation.where(members: scope) } + end Gitlab::SQL::Union.new(relations) end |