From eba5672077f5d7956fc8f7db583136b3ccb451b5 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 12 Mar 2019 08:13:21 +0000 Subject: Allow filtering labels by a single character When we use Gitlab::SQL::Pattern, this typically relates to a trigram index. As the 'tri' indicates, we need at least three characters to be able to use that index. Labels don't have a trigram index, because we never allow you to search for them globally: it's always in the context of a project or a group. In that context, it's just as fast to search for a single character (in general) because there is already a pretty specific index being used. --- app/models/label.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/label.rb') diff --git a/app/models/label.rb b/app/models/label.rb index 1c3db3eb35d..96bdb7f17c5 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -126,6 +126,13 @@ class Label < ActiveRecord::Base fuzzy_search(query, [:title, :description]) end + # Override Gitlab::SQL::Pattern.min_chars_for_partial_matching as + # label queries are never global, and so will not use a trigram + # index. That means we can have just one character in the LIKE. + def self.min_chars_for_partial_matching + 1 + end + def open_issues_count(user = nil) issues_count(user, state: 'opened') end -- cgit v1.2.3