]> cat aescling's git repositories - mastodon.git/commitdiff
Add `account_id DESC` to optimize PrecomputeFeedService (#2967)
authoralpaca-tc <alpaca-tc@alpaca.tc>
Wed, 10 May 2017 18:33:32 +0000 (03:33 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 10 May 2017 18:33:32 +0000 (20:33 +0200)
app/services/precompute_feed_service.rb

index 07dcb81dafed4b9ccadf9bf02ae812305618f4c9..46f0057cba27466b39eb04557e7140260601a405 100644 (file)
@@ -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