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)
limit(tags)
end
search! private
limit!
@tags def all_tags
::ActsAsTaggableOn::Tag.all
end end
def search! def filter_by_name(tags)
search = @params[:search] return tags unless search
return tags.none if search.empty?
return unless search
if search.empty? if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING
@tags = ::ActsAsTaggableOn::Tag.none tags.named_like(search)
return else
tags.named(search)
end end
end
@tags = def limit(tags)
if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
@tags.named_like(search)
else
@tags.named(search)
end
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