Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Improve `Promotion#blacklisted?` method lookups times (#13093)

Damian Legawiec19c6171553a1
diff --git a/core/app/models/spree/promotion.rb b/core/app/models/spree/promotion.rb
index 5febed1024..ac43c6799e 100644
--- a/core/app/models/spree/promotion.rb
+++ b/core/app/models/spree/promotion.rb
@@ -340,7 +340,7 @@ module Spree
when Spree::LineItem
!promotable.product.promotionable?
when Spree::Order
- promotable.line_items.any? &&
+ (promotable.item_count.positive? || promotable.line_items.any?) &&
promotable.line_items.joins(:product).where(spree_products: { promotionable: true }).none?
end
end
diff --git a/core/db/migrate/20250911205659_add_missing_index_on_spree_products_promotionable.rb b/core/db/migrate/20250911205659_add_missing_index_on_spree_products_promotionable.rb
new file mode 100644
index 0000000000..7aac076ba6
--- /dev/null
+++ b/core/db/migrate/20250911205659_add_missing_index_on_spree_products_promotionable.rb
@@ -0,0 +1,5 @@
+class AddMissingIndexOnSpreeProductsPromotionable < ActiveRecord::Migration[7.2]
+ def change
+ add_index :spree_products, :promotionable, if_not_exists: true
+ end
+end