From 7bcb0bcaa83b13d4094d4bd4c1646c1c3894f453 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 4 Jun 2021 14:17:49 +0100 Subject: [PATCH] Eager-load the adjustment's adjustable Reduces the total migration time by ~15%. Requires including some more models, as order objects are now being eager-loaded as part of the polymorphic associations. --- .../20210406161242_migrate_enterprise_fee_tax_amounts.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/migrate/20210406161242_migrate_enterprise_fee_tax_amounts.rb b/db/migrate/20210406161242_migrate_enterprise_fee_tax_amounts.rb index 93cf62d095..f0f99e2bc3 100644 --- a/db/migrate/20210406161242_migrate_enterprise_fee_tax_amounts.rb +++ b/db/migrate/20210406161242_migrate_enterprise_fee_tax_amounts.rb @@ -2,6 +2,8 @@ # associations. The only workaround seems to be to load the class explicitly, which essentially # skips the whole point of good_migrations... :/ require 'enterprise_fee' +require 'concerns/balance' +require 'spree/order' class MigrateEnterpriseFeeTaxAmounts < ActiveRecord::Migration[5.0] class Spree::Adjustment < ApplicationRecord @@ -39,7 +41,9 @@ class MigrateEnterpriseFeeTaxAmounts < ActiveRecord::Migration[5.0] end def migrate_enterprise_fee_taxes! - Spree::Adjustment.enterprise_fee.where('included_tax <> 0').includes(:originator).find_each do |fee| + Spree::Adjustment.enterprise_fee.where('included_tax <> 0'). + includes(:originator, :adjustable).find_each do |fee| + tax_category = tax_category_for(fee) tax_rate = tax_rate_for(tax_category)