about summary refs log tree commit diff
path: root/app/controllers/api/v1/follow_requests_controller.rb
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2017-05-20 22:13:51 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-05-20 15:13:51 +0200
commitf55480756337dd4df7513e89673e81e003f1201a (patch)
treebfd4aabb606f82f2fe01a16bcceec340ec11ecd3 /app/controllers/api/v1/follow_requests_controller.rb
parentd972845ff663605becec1dde904271897fe2e347 (diff)
Use joins for account properties (#3167)
Diffstat (limited to 'app/controllers/api/v1/follow_requests_controller.rb')
-rw-r--r--app/controllers/api/v1/follow_requests_controller.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/app/controllers/api/v1/follow_requests_controller.rb b/app/controllers/api/v1/follow_requests_controller.rb
index 73cfaf10a..4716019a8 100644
--- a/app/controllers/api/v1/follow_requests_controller.rb
+++ b/app/controllers/api/v1/follow_requests_controller.rb
@@ -5,12 +5,13 @@ class Api::V1::FollowRequestsController < ApiController
   before_action :require_user!
 
   def index
-    results   = FollowRequest.where(target_account: current_account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
-    accounts  = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
-    @accounts = results.map { |f| accounts[f.account_id] }
+    @accounts = Account.includes(:follow_requests)
+                       .references(:follow_requests)
+                       .merge(FollowRequest.where(target_account: current_account)
+                                           .paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id]))
 
-    next_path = api_v1_follow_requests_url(pagination_params(max_id: results.last.id))    if results.size == DEFAULT_ACCOUNTS_LIMIT
-    prev_path = api_v1_follow_requests_url(pagination_params(since_id: results.first.id)) unless results.empty?
+    next_path = api_v1_follow_requests_url(pagination_params(max_id: @accounts.last.follow_requests.last.id))     if @accounts.size == DEFAULT_ACCOUNTS_LIMIT
+    prev_path = api_v1_follow_requests_url(pagination_params(since_id: @accounts.first.follow_requests.first.id)) unless @accounts.empty?
 
     set_pagination_headers(next_path, prev_path)
   end