From aedd2cfa5b82c01f82ec26b64880fce2a07fe942 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 24 Nov 2017 11:45:19 +0100 Subject: Use Gitlab::SQL::Pattern where appropriate --- app/models/namespace.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 4d401e7ba18..15bc7032a43 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -9,6 +9,7 @@ class Namespace < ActiveRecord::Base include Routable include AfterCommitQueue include Storage::LegacyNamespace + include Gitlab::SQL::Pattern # Prevent users from creating unreasonably deep level of nesting. # The number 20 was taken based on maximum nesting level of @@ -87,7 +88,7 @@ class Namespace < ActiveRecord::Base # Returns an ActiveRecord::Relation def search(query) t = arel_table - pattern = "%#{query}%" + pattern = to_pattern(query) where(t[:name].matches(pattern).or(t[:path].matches(pattern))) end -- cgit v1.2.1 From da42dfb3cf4a2fb0cdcc1a3b41438516a0bed0e5 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 24 Nov 2017 12:24:24 +0100 Subject: Use fuzzy search with minimum length of 3 characters where appropriate --- app/models/namespace.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 15bc7032a43..fa76729a702 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -87,10 +87,7 @@ class Namespace < ActiveRecord::Base # # Returns an ActiveRecord::Relation def search(query) - t = arel_table - pattern = to_pattern(query) - - where(t[:name].matches(pattern).or(t[:path].matches(pattern))) + fuzzy_search(query, [:name, :path]) end def clean_path(path) -- cgit v1.2.1 From 20f78421c82d626a3b43924146b7878fe4777ae8 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 30 Nov 2017 14:26:08 +0100 Subject: Cache the forks in a namespace in the RequestStore On the `show` of a project that is part of a fork network. We check if the user already created a fork of this project in their personal namespace. We do this in several places, so caching the result of this query in the request store prevents us from repeating it. --- app/models/namespace.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index fa76729a702..901dbf2ba69 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -139,7 +139,17 @@ class Namespace < ActiveRecord::Base def find_fork_of(project) return nil unless project.fork_network - project.fork_network.find_forks_in(projects).first + if RequestStore.active? + forks_in_namespace = RequestStore.fetch("namespaces:#{id}:forked_projects") do + Hash.new do |found_forks, project| + found_forks[project] = project.fork_network.find_forks_in(projects).first + end + end + + forks_in_namespace[project] + else + project.fork_network.find_forks_in(projects).first + end end def lfs_enabled? -- cgit v1.2.1