summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-11-24 11:23:14 +0100
committerDouwe Maan <douwe@selenight.nl>2017-11-24 15:57:17 +0100
commit8041a87288906e4b10b86a9a2ab9039036243a5d (patch)
treeec018c0168531b233160cd67a2d46217272a936b /app/models/project.rb
parent3dd5bedb54ce1bb150ab5304463c0a63d6e10ec9 (diff)
downloadgitlab-ce-8041a87288906e4b10b86a9a2ab9039036243a5d.tar.gz
Drastically improve project search performance by no longer searching namespace namedm-project-search-performance
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb30
1 files changed, 8 insertions, 22 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 43a4d86c138..e276bd2422d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -18,6 +18,7 @@ class Project < ActiveRecord::Base
include SelectForProjectAuthorization
include Routable
include GroupDescendant
+ include Gitlab::SQL::Pattern
extend Gitlab::ConfigHelper
extend Gitlab::CurrentSettings
@@ -424,32 +425,17 @@ class Project < ActiveRecord::Base
#
# query - The search query as a String.
def search(query)
- ptable = arel_table
- ntable = Namespace.arel_table
- pattern = "%#{query}%"
-
- # 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))
- )
-
- namespaces = unscoped.select(:id)
- .joins(:namespace)
- .where(ntable[:name].matches(pattern))
-
- union = Gitlab::SQL::Union.new([projects, namespaces])
+ pattern = to_pattern(query)
- where("projects.id IN (#{union.to_sql})") # rubocop:disable GitlabSecurity/SqlInjection
+ where(
+ arel_table[:path].matches(pattern)
+ .or(arel_table[:name].matches(pattern))
+ .or(arel_table[:description].matches(pattern))
+ )
end
def search_by_title(query)
- pattern = "%#{query}%"
- table = Project.arel_table
-
- non_archived.where(table[:name].matches(pattern))
+ non_archived.where(arel_table[:name].matches(to_pattern(query)))
end
def visibility_levels