summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-03-24 12:27:54 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-03-24 12:27:54 +0000
commit8cc4a39be8d1bf31fe082829be209c6969647ab4 (patch)
tree18e5bd808828c2388fd42f17560a56ee6208f0ec /app/models/project.rb
parentd561881b13ce6f5346e915efbfc1a38ceb18bb02 (diff)
parentdf0603cf0e9b3ae2e2ee6b14135a2d2a885d8965 (diff)
downloadgitlab-ce-8cc4a39be8d1bf31fe082829be209c6969647ab4.tar.gz
Merge branch '22145-slow-search' into 'master'
Simplify projects, merge requests search queries See merge request !10053
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb13
1 files changed, 4 insertions, 9 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 04641dd58a0..f1bba56d32c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -314,20 +314,15 @@ class Project < ActiveRecord::Base
ntable = Namespace.arel_table
pattern = "%#{query}%"
- projects = select(:id).where(
+ # unscoping unnecessary conditions that'll be applied
+ # when executing `where("projects.id IN (#{union.to_sql})")`
+ projects = unscoped.select(:id).where(
ptable[:path].matches(pattern).
or(ptable[:name].matches(pattern)).
or(ptable[:description].matches(pattern))
)
- # We explicitly remove any eager loading clauses as they're:
- #
- # 1. Not needed by this query
- # 2. Combined with .joins(:namespace) lead to all columns from the
- # projects & namespaces tables being selected, leading to a SQL error
- # due to the columns of all UNION'd queries no longer being the same.
- namespaces = select(:id).
- except(:includes).
+ namespaces = unscoped.select(:id).
joins(:namespace).
where(ntable[:name].matches(pattern))