logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe
commit: d2159deaf272de265ba11f16a92d60ea61def19f
parent: 17c591ffba59bda512fe43a09c06c40324acc472
Author: 178inaba <magic.brain.evolution.7.0@gmail.com>
Date:   Tue, 25 Apr 2017 11:44:43 +0900

Optimize account search (#2421)


Diffstat:

Mapp/services/account_search_service.rb8+++++---
Mspec/services/account_search_service_spec.rb6++++++
2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb @@ -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? diff --git a/spec/services/account_search_service_spec.rb b/spec/services/account_search_service_spec.rb @@ -13,6 +13,12 @@ describe AccountSearchService do 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 describe 'searching for a simple term that is not an exact match' do