diff options
-rw-r--r-- | app/models/project.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 2ba6a863500..2dc3dd38099 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 |