about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
author178inaba <magic.brain.evolution.7.0@gmail.com>2017-04-25 11:44:43 +0900
committerEugen <eugen@zeonfederated.com>2017-04-25 04:44:43 +0200
commitd2159deaf272de265ba11f16a92d60ea61def19f (patch)
treea01b095c6dd76cac6c3b2d8e16f4ed9ded32565a /app/services
parent17c591ffba59bda512fe43a09c06c40324acc472 (diff)
Optimize account search (#2421)
Diffstat (limited to 'app/services')
-rw-r--r--app/services/account_search_service.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb
index 58a23d978..e695d22ca 100644
--- 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?