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.

Remove unnecessary caching from `Product#default_variant` method

Damian Legawiece5278a13d33e
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 4897634156..90221a005a 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -230,7 +230,7 @@ module Spree
#
# @return [Spree::Variant]
def default_variant
- @default_variant ||= Rails.cache.fetch(default_variant_cache_key) do
+ @default_variant ||= begin
if Spree::Config[:track_inventory_levels] && available_variant = variants.detect(&:purchasable?)
available_variant
else
@@ -492,6 +492,8 @@ module Spree
end
def default_variant_cache_key
+ Spree::Deprecation.warn('Spree::Product#default_variant_cache_key is deprecated and will be removed in Spree 6. Please remove any occurrences of it.')
+
"spree/default-variant/#{cache_key_with_version}/#{Spree::Config[:track_inventory_levels]}"
end
diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb
index 3a194c2bd4..24c541460c 100644
--- a/core/spec/models/spree/product_spec.rb
+++ b/core/spec/models/spree/product_spec.rb
@@ -824,39 +824,6 @@ describe Spree::Product, type: :model do
end
end
- describe '#default_variant_cache_key' do
- let(:product) { create(:product, stores: [store]) }
- let(:key) { product.send(:default_variant_cache_key) }
-
- context 'with inventory tracking' do
- before { Spree::Config[:track_inventory_levels] = true }
-
- it 'returns proper key' do
- expect(key).to eq("spree/default-variant/#{product.cache_key_with_version}/true")
- end
- end
-
- context 'without invenrtory tracking' do
- before { Spree::Config[:track_inventory_levels] = false }
-
- it 'returns proper key' do
- expect(key).to eq("spree/default-variant/#{product.cache_key_with_version}/false")
- end
- end
-
- describe '#requires_shipping_category?' do
- let(:product) { build(:product, shipping_category: nil) }
-
- it { expect(product.save).to eq(false) }
- end
-
- describe '#downcase_slug' do
- let(:product) { build(:product, slug: 'My-slug') }
-
- it { expect { product.valid? }.to change(product, :slug).to('my-slug') }
- end
- end
-
describe '#default_image' do
let(:product) { create(:product, stores: [store]) }
let!(:image) { create(:image, viewable: product.master) }