summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-02-13 16:13:17 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-02-20 13:08:24 +0100
commitd13aebabc36b6f5fcf41ba32a9c6ee45b91daf3f (patch)
tree2c20ff02171881f663fa35bbe546f5332e2b90a2
parent5048c8d5050cd432381d845997c5e7991e6590f1 (diff)
downloadgitlab-ce-d13aebabc36b6f5fcf41ba32a9c6ee45b91daf3f.tar.gz
Replace OR clause with UNION.
-rw-r--r--app/models/project.rb8
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