From 090eeb581b3809ab83d52f7baa2bcfbd63b1c2ba Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 15 Feb 2018 19:55:43 +0100 Subject: Added changelog for user search improvements --- app/finders/autocomplete_users_finder.rb | 2 +- changelogs/unreleased/users-autocomplete.yml | 5 +++++ lib/gitlab/sql/pattern.rb | 6 ++---- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 changelogs/unreleased/users-autocomplete.yml diff --git a/app/finders/autocomplete_users_finder.rb b/app/finders/autocomplete_users_finder.rb index 49eb6af8f11..e8a03947f59 100644 --- a/app/finders/autocomplete_users_finder.rb +++ b/app/finders/autocomplete_users_finder.rb @@ -58,7 +58,7 @@ class AutocompleteUsersFinder def users_from_project if author_id.present? union = Gitlab::SQL::Union - .new([project.team.users, User.where(id: author_id)]) + .new([project.authorized_users, User.where(id: author_id)]) User.from("(#{union.to_sql}) #{User.table_name}") else diff --git a/changelogs/unreleased/users-autocomplete.yml b/changelogs/unreleased/users-autocomplete.yml new file mode 100644 index 00000000000..2cb078a3a7c --- /dev/null +++ b/changelogs/unreleased/users-autocomplete.yml @@ -0,0 +1,5 @@ +--- +title: Improve performance of searching for and autocompleting of users +merge_request: +author: +type: performance diff --git a/lib/gitlab/sql/pattern.rb b/lib/gitlab/sql/pattern.rb index 0e3a93aa236..53744bad1f4 100644 --- a/lib/gitlab/sql/pattern.rb +++ b/lib/gitlab/sql/pattern.rb @@ -38,16 +38,14 @@ module Gitlab if words.any? words.map { |word| arel_table[column].matches(to_pattern(word)) }.reduce(:and) else - sanitized_query = sanitize_sql_like(query) - # No words of at least 3 chars, but we can search for an exact # case insensitive match with the query as a whole if lower_exact_match Arel::Nodes::NamedFunction .new('LOWER', [arel_table[column]]) - .eq(sanitized_query) + .eq(query) else - arel_table[column].matches(sanitized_query) + arel_table[column].matches(sanitize_sql_like(query)) end end end -- cgit v1.2.1