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
Added caching of `Variant#price_in` (#11599)
Damian Legawiecf24e08184f87
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex 5ea20f98f7..21b887226f 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -209,7 +209,20 @@ module Spreeenddef price_in(currency)- prices.detect { |price| price.currency == currency&.upcase } || prices.build(currency: currency&.upcase)+ currency = currency&.upcase+ find_or_build_price = lambda do+ if prices.loaded?+ prices.detect { |price| price.currency == currency } || prices.build(currency: currency)+ else+ prices.find_or_initialize_by(currency: currency)+ end+ end++ Rails.cache.fetch("spree/prices/#{cache_key_with_version}/price_in/#{currency}") do+ find_or_build_price.call+ end+ rescue TypeError+ find_or_build_price.callenddef amount_in(currency)