about summary refs log tree commit diff
diff options
context:
space:
mode:
authoralpaca-tc <alpaca-tc@alpaca.tc>2017-05-11 03:33:32 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-05-10 20:33:32 +0200
commitc3ef5d5414ac1fee5471d7063616a4b72a408e11 (patch)
tree95b65b161799e398410f960c0c42e1dc38f7159f
parent57a3d71c90844a140ee8d6c1cdded67a4565c6ca (diff)
Add `account_id DESC` to optimize PrecomputeFeedService (#2967)
-rw-r--r--app/services/precompute_feed_service.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/app/services/precompute_feed_service.rb b/app/services/precompute_feed_service.rb
index 07dcb81da..46f0057cb 100644
--- a/app/services/precompute_feed_service.rb
+++ b/app/services/precompute_feed_service.rb
@@ -6,7 +6,8 @@ class PrecomputeFeedService < BaseService
   # @param [Account] account
   def call(_, account)
     redis.pipelined do
-      Status.as_home_timeline(account).limit(FeedManager::MAX_ITEMS / 4).each do |status|
+      # NOTE: Added `id desc, account_id desc` to `ORDER BY` section to optimize query.
+      Status.as_home_timeline(account).order(account_id: :desc).limit(FeedManager::MAX_ITEMS / 4).each do |status|
         next if status.direct_visibility? || FeedManager.instance.filter?(:home, status, account.id)
         redis.zadd(FeedManager.instance.key(:home, account.id), status.id, status.reblog? ? status.reblog_of_id : status.id)
       end