Commit 33a4fe1f authored by Stan Hu's avatar Stan Hu

Skip querying for private projects if they are not requested

If the requested visibility levels contains only public and/or internal,
omitting private, then we can skip the EXISTS query to search for
private projects for the user.
parent c408be48
...@@ -471,14 +471,29 @@ class Project < ActiveRecord::Base ...@@ -471,14 +471,29 @@ class Project < ActiveRecord::Base
return public_to_user unless user return public_to_user unless user
visible_levels = Gitlab::VisibilityLevel.levels_for_user(user) visible_levels = Gitlab::VisibilityLevel.levels_for_user(user)
visible_levels &= Array(requested_visibility_levels) if requested_visibility_levels.present? include_private = true
requested_visibility_levels = Array(requested_visibility_levels)
if requested_visibility_levels.present?
visible_levels &= requested_visibility_levels
include_private = requested_visibility_levels.include?(Gitlab::VisibilityLevel::PRIVATE)
end
public_or_internal_rel =
if visible_levels.present? if visible_levels.present?
where('EXISTS (?) OR projects.visibility_level IN (?)', where('projects.visibility_level IN (?)', visible_levels)
user.authorizations_for_projects, visible_levels)
else else
Project.none
end
private_rel =
if include_private
where('EXISTS (?)', user.authorizations_for_projects) where('EXISTS (?)', user.authorizations_for_projects)
else
Project.none
end end
public_or_internal_rel.or(private_rel)
end end
# project features may be "disabled", "internal", "enabled" or "public". If "internal", # project features may be "disabled", "internal", "enabled" or "public". If "internal",
......
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