Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(accounts): resolve N+1 query for Trade entryables (#2973)

sentry[bot]68b28c946c7f
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index 223483f6b3..67d42d75de 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -96,6 +96,14 @@ class AccountsController < ApplicationController
).call
end
+ trades = @entries.filter_map { |e| e.entryable if e.entryable_type == "Trade" }
+ if trades.any?
+ ActiveRecord::Associations::Preloader.new(
+ records: trades,
+ associations: [ :security ]
+ ).call
+ end
+
entry_ids = @entries.map(&:id)
@split_parent_entry_ids = if entry_ids.any?
Entry.where(parent_entry_id: entry_ids).distinct.pluck(:parent_entry_id).to_set