Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Adjustment updater: only run SQL update if totals changed (#13100)
Damian Legawiecba63416cfb5a
diff --git a/core/app/models/spree/adjustable/adjustments_updater.rb b/core/app/models/spree/adjustable/adjustments_updater.rbindex d00dbe3fcd..477fe95054 100644--- a/core/app/models/spree/adjustable/adjustments_updater.rb+++ b/core/app/models/spree/adjustable/adjustments_updater.rb@@ -31,6 +31,11 @@ module Spreeattributes[:adjustment_total] = totals[:non_taxable_adjustment_total] +totals[:taxable_adjustment_total] +totals[:additional_tax_total]++ # Only update if totals have changed+ current_attributes = @adjustable.attributes.slice(*attributes.keys.map(&:to_s))+ return if attributes.all? { |key, value| current_attributes[key.to_s] == value }+attributes[:updated_at] = Time.current@adjustable.update_columns(totals)enddiff --git a/core/spec/models/spree/adjustable/adjustments_updater_spec.rb b/core/spec/models/spree/adjustable/adjustments_updater_spec.rbindex ddfb06c92c..1749047e75 100644--- a/core/spec/models/spree/adjustable/adjustments_updater_spec.rb+++ b/core/spec/models/spree/adjustable/adjustments_updater_spec.rb@@ -18,10 +18,24 @@ module Spreeit 'updates all linked adjusters' doline_item.price = 10line_item.tax_category = tax_rate.tax_category+ line_item.adjustment_total = 0+ line_item.additional_tax_total = 0++ old_updated_at = line_item.updated_at++ subject.update+ expect(line_item.adjustment_total).to eq(0.5)+ expect(line_item.additional_tax_total).to eq(0.5)+ expect(line_item.updated_at).not_to eq(old_updated_at)++ old_updated_at = line_item.updated_atsubject.update+ # skipping the update because the totals have not changed+ line_item.reloadexpect(line_item.adjustment_total).to eq(0.5)expect(line_item.additional_tax_total).to eq(0.5)+ expect(line_item.updated_at).to eq(old_updated_at)endend