Commit 9e00a237 authored by Yorick Peterse's avatar Yorick Peterse Committed by Robert Speicher
Browse files

Clean up ProjectsFinder for getting user projects

We don't need the extra layer of nesting of UNION queries here (as
User#authorized_projects already returns a UNION'd query).
parent 4f3e28c4c7f3
......@@ -52,7 +52,10 @@ def group_projects(current_user, group)
def all_projects(current_user)
if current_user
[current_user.authorized_projects, public_and_internal_projects]
[
*current_user.project_relations,
public_and_internal_projects
]
else
[Project.public_only]
end
......
......@@ -442,6 +442,11 @@ def authorized_projects
Project.where("projects.id IN (#{projects_union.to_sql})")
end
# Returns all the project relations
def project_relations
[personal_projects, groups_projects, projects]
end
def owned_projects
@owned_projects ||=
Project.where('namespace_id IN (?) OR namespace_id = ?',
......@@ -830,9 +835,7 @@ def ci_authorized_runners
private
def projects_union
Gitlab::SQL::Union.new([personal_projects.select(:id),
groups_projects.select(:id),
projects.select(:id)])
Gitlab::SQL::Union.new(project_relations.map { |r| r.select(:id) })
end
def ci_projects_union
......
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