diff options
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb b/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb index 71dffb72dce..f38c187799c 100644 --- a/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb +++ b/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb @@ -10,34 +10,34 @@ module Autocomplete end def execute - @tags = ::ActsAsTaggableOn::Tag.all + tags = all_tags + tags = filter_by_name(tags) + limit(tags) + end - search! - limit! + private - @tags + def all_tags + ::ActsAsTaggableOn::Tag.all end - def search! - search = @params[:search] - - return unless search + def filter_by_name(tags) + return tags unless search + return tags.none if search.empty? - if search.empty? - @tags = ::ActsAsTaggableOn::Tag.none - return + if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING + tags.named_like(search) + else + tags.named(search) end + end - @tags = - if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING - @tags.named_like(search) - else - @tags.named(search) - end + def limit(tags) + tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord end - def limit! - @tags = @tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord + def search + @params[:search] end end end |