Skip to content
Snippets Groups Projects
Commit d2159dea authored by 178inaba's avatar 178inaba Committed by Eugen
Browse files

Optimize account search (#2421)

parent 17c591ff
No related branches found
No related tags found
No related merge requests found
......@@ -15,12 +15,12 @@ class AccountSearchService < BaseService
private
def search_service_results
return [] if query_blank_or_hashtag?
return [] if query_blank_or_hashtag? || limit < 1
if resolving_non_matching_remote_account?
[FollowRemoteAccountService.new.call("#{query_username}@#{query_domain}")]
else
search_results_and_exact_match.compact.uniq
search_results_and_exact_match.compact.uniq.slice(0, limit)
end
end
......@@ -29,7 +29,9 @@ class AccountSearchService < BaseService
end
def search_results_and_exact_match
[exact_match] + search_results.to_a
exact = [exact_match]
return exact if !exact[0].nil? && limit == 1
exact + search_results.to_a
end
def query_blank_or_hashtag?
......
......@@ -11,6 +11,12 @@ describe AccountSearchService do
it 'returns empty array for hashtag query' do
results = subject.call('#tag', 10)
expect(results).to eq []
end
it 'returns empty array for limit zero' do
Fabricate(:account, username: 'match')
results = subject.call('match', 0)
expect(results).to eq []
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment