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
Fixed issue #13437 - Promotion rule caching issue when editing rules … (#13439)
Damian Legawiecea3861fe2316
diff --git a/core/app/models/spree/promotion/rules/product.rb b/core/app/models/spree/promotion/rules/product.rbindex f461e63d85..e74443a690 100644--- a/core/app/models/spree/promotion/rules/product.rb+++ b/core/app/models/spree/promotion/rules/product.rb@@ -100,6 +100,9 @@ module Spree)end+ # Invalidate cache after bulk operations+ touch+# Clear memoized values@eligible_product_ids = nilenddiff --git a/core/app/models/spree/promotion/rules/user.rb b/core/app/models/spree/promotion/rules/user.rbindex e99cfaeb00..aca7829142 100644--- a/core/app/models/spree/promotion/rules/user.rb+++ b/core/app/models/spree/promotion/rules/user.rb@@ -61,6 +61,9 @@ module Spree)end+ # Invalidate cache after bulk operations+ touch+# Clear memoized values@eligible_user_ids = nilenddiff --git a/core/spec/models/spree/promotion/rules/product_spec.rb b/core/spec/models/spree/promotion/rules/product_spec.rbindex 2696939609..9fa1755b3a 100644--- a/core/spec/models/spree/promotion/rules/product_spec.rb+++ b/core/spec/models/spree/promotion/rules/product_spec.rb@@ -178,5 +178,17 @@ describe Spree::Promotion::Rules::Product, type: :model dorule.save!expect(rule.reload.eligible_product_ids).to match_array(products.map(&:id))end++ it 'touches the record to invalidate cache' do+ rule.product_ids_to_add = [products.first.id]+ rule.save!+ original_updated_at = rule.updated_at++ rule.update_column(:updated_at, 1.day.ago)+ rule.product_ids_to_add = [products.second.id]+ rule.save!++ expect(rule.reload.updated_at).to be > original_updated_at+ endendenddiff --git a/core/spec/models/spree/promotion/rules/user_spec.rb b/core/spec/models/spree/promotion/rules/user_spec.rbindex ec9ca97b66..5a1ac30740 100644--- a/core/spec/models/spree/promotion/rules/user_spec.rb+++ b/core/spec/models/spree/promotion/rules/user_spec.rb@@ -63,5 +63,17 @@ describe Spree::Promotion::Rules::User, type: :model dorule.save!expect(rule.users).to include(random_user, user_placing_order)end++ it 'touches the record to invalidate cache' do+ rule.user_ids_to_add = [random_user.id]+ rule.save!+ original_updated_at = rule.updated_at++ rule.update_column(:updated_at, 1.day.ago)+ rule.user_ids_to_add = [user_placing_order.id]+ rule.save!++ expect(rule.reload.updated_at).to be > original_updated_at+ endendend