Commit d13aebab authored by Andreas Brandl's avatar Andreas Brandl

Replace OR clause with UNION.

parent 5048c8d5
......@@ -325,7 +325,13 @@ class Project < ActiveRecord::Base
levels = Gitlab::VisibilityLevel.levels_for_user(user)
where('EXISTS (?) OR projects.visibility_level IN (?)', authorized, levels)
authorized_projects = where('EXISTS (?)', authorized).select(:id)
visible_projects = where('visibility_level IN (?)', levels).select(:id)
# We use a UNION here instead of OR clauses since this results in better
# performance.
union = Gitlab::SQL::Union.new([authorized_projects, visible_projects])
where("projects.id IN (#{union.to_sql})") # rubocop:disable GitlabSecurity/SqlInjection
else
public_to_user
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