about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/search_service.rb20
1 files changed, 8 insertions, 12 deletions
diff --git a/app/services/search_service.rb b/app/services/search_service.rb
index d9b627853..9e8ee6220 100644
--- a/app/services/search_service.rb
+++ b/app/services/search_service.rb
@@ -1,25 +1,21 @@
 class SearchService < BaseService
-  def call(query, resolve = false)
+  def call(query, limit, resolve = false)
     return if query.blank?
 
     username, domain = query.split('@')
 
-    if domain.nil?
-      search_all(username)
+    results = if domain.nil?
+      Account.search_for(username)
     else
-      search_or_resolve(username, domain, resolve)
+      Account.search_for("#{username} #{domain}")
     end
-  end
 
-  private
+    results = results.limit(limit).with_counters
 
-  def search_all(username)
-    Account.search_for(username)
-  end
+    if resolve && results.empty? && !domain.nil?
+      results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
+    end
 
-  def search_or_resolve(username, domain, resolve)
-    results = Account.search_for("#{username} #{domain}")
-    return [FollowRemoteAccountService.new.call("#{username}@#{domain}")] if results.empty? && resolve
     results
   end
 end