]> cat aescling's git repositories - mastodon.git/commitdiff
Fix N+1 query when rendering with StatusSerializer (#15641)
authorabcang <abcang1015@gmail.com>
Sun, 31 Jan 2021 20:24:17 +0000 (05:24 +0900)
committerGitHub <noreply@github.com>
Sun, 31 Jan 2021 20:24:17 +0000 (21:24 +0100)
app/models/status.rb

index fcc7a026d5c0897a7c7ea4ec6df0a53c10833d33..74e81f6127cdb5c7d01538cb1fc61c70b882954d 100644 (file)
@@ -114,7 +114,7 @@ class Status < ApplicationRecord
                    :tags,
                    :preview_cards,
                    :preloadable_poll,
-                   account: :account_stat,
+                   account: [:account_stat, :user],
                    active_mentions: { account: :account_stat },
                    reblog: [
                      :application,
@@ -124,7 +124,7 @@ class Status < ApplicationRecord
                      :conversation,
                      :status_stat,
                      :preloadable_poll,
-                     account: :account_stat,
+                     account: [:account_stat, :user],
                      active_mentions: { account: :account_stat },
                    ],
                    thread: { account: :account_stat }
@@ -301,7 +301,7 @@ class Status < ApplicationRecord
 
       return if account_ids.empty?
 
-      accounts = Account.where(id: account_ids).includes(:account_stat).index_by(&:id)
+      accounts = Account.where(id: account_ids).includes(:account_stat, :user).index_by(&:id)
 
       cached_items.each do |item|
         item.account = accounts[item.account_id]