about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-03-24 13:21:53 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-03-24 13:21:53 +0100
commit0f5bbb999c9770654613cb373070984dd785e855 (patch)
tree90c4dac78f605ea357868502da9607d6812a1a8b /app/controllers
parent7e58303a8da90b31f4179695283d3ac19dfb09d1 (diff)
Pre-loading polymorphic associations for Atom feeds
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/accounts_controller.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 53f665238..6794234e4 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -7,7 +7,14 @@ class AccountsController < ApplicationController
   def show
     respond_to do |format|
       format.html { @statuses = @account.statuses.order('id desc').with_includes.with_counters.paginate(page: params[:page], per_page: 10)}
-      format.atom { @entries  = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id] || nil) }
+
+      format.atom do
+        @entries = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id] || nil)
+
+        ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Status' }, :mentioned_accounts, reblog: :account, thread: :account)
+        ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Favourite' }, status: [:account, :thread, :mentioned_accounts])
+        ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Follow' }, :target_account)
+      end
     end
   end