Commit 28fcf5c4 authored by Alexis Reigel's avatar Alexis Reigel

use functional style for tags finder

parent 4667b20c
...@@ -10,34 +10,34 @@ module Autocomplete ...@@ -10,34 +10,34 @@ module Autocomplete
end end
def execute def execute
@tags = ::ActsAsTaggableOn::Tag.all tags = all_tags
tags = filter_by_name(tags)
search! limit(tags)
limit!
@tags
end end
def search! private
search = @params[:search]
return unless search
if search.empty? def all_tags
@tags = ::ActsAsTaggableOn::Tag.none ::ActsAsTaggableOn::Tag.all
return
end end
@tags = def filter_by_name(tags)
return tags unless search
return tags.none if search.empty?
if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING
@tags.named_like(search) tags.named_like(search)
else else
@tags.named(search) tags.named(search)
end
end end
def limit(tags)
tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end end
def limit! def search
@tags = @tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord @params[:search]
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment