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

use functional style for tags finder

parent 4667b20c
No related merge requests found
......@@ -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
......
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