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 more memoization to speed up product listings (#12811)
Damian Legawiec47b8f41bd038
diff --git a/core/app/models/spree/wishlist.rb b/core/app/models/spree/wishlist.rbindex a820f935cc..37e244be0f 100644--- a/core/app/models/spree/wishlist.rb+++ b/core/app/models/spree/wishlist.rb@@ -36,6 +36,13 @@ module Spree@wished_items_count ||= variant_ids.countend+ # returns the variant ids in the wishlist+ #+ # @return [Array<Integer>]+ def variant_ids+ @variant_ids ||= wished_items.pluck(:variant_id)+ end+def self.get_by_param(param)find_by(token: param)enddiff --git a/core/spec/models/spree/wishlist_spec.rb b/core/spec/models/spree/wishlist_spec.rbindex 77e9a6fc61..b5d12534e3 100644--- a/core/spec/models/spree/wishlist_spec.rb+++ b/core/spec/models/spree/wishlist_spec.rb@@ -123,4 +123,18 @@ describe Spree::Wishlist, type: :model doexpect(wishlist.wished_items_count).to eq 1endend++ describe '#variant_ids' do+ let(:variant) { create(:variant) }+ let(:variant_2) { create(:variant) }++ before do+ wishlist.wished_items << create(:wished_item, variant: variant)+ wishlist.wished_items << create(:wished_item, variant: variant_2)+ end++ it 'returns the variant ids' do+ expect(wishlist.variant_ids).to eq [variant.id, variant_2.id]+ end+ endenddiff --git a/storefront/app/controllers/spree/store_controller.rb b/storefront/app/controllers/spree/store_controller.rbindex ee7a77a4e2..84be0a131f 100644--- a/storefront/app/controllers/spree/store_controller.rb+++ b/storefront/app/controllers/spree/store_controller.rb@@ -123,29 +123,31 @@ module Spreeenddef storefront_products_scope- current_store.products.active(current_currency)+ @storefront_products_scope ||= current_store.products.active(current_currency)enddef default_products_finder_params- taxon = @taxon || current_taxon+ @default_products_finder_params ||= begin+ taxon = @taxon || current_taxon- filter = permitted_products_params.fetch(:filter, {}).dup+ filter = permitted_products_params.fetch(:filter, {}).dup- filter[:taxon_ids] ||= [taxon&.id.to_s].compact- filter[:taxons] = filter[:taxon_ids].join(',')+ filter[:taxon_ids] ||= [taxon&.id.to_s].compact+ filter[:taxons] = filter[:taxon_ids].join(',')- if filter.key?(:min_price) || filter.key?(:max_price)- min_price = filter[:min_price].presence || 0- max_price = filter[:max_price].presence || 'Infinity'+ if filter.key?(:min_price) || filter.key?(:max_price)+ min_price = filter[:min_price].presence || 0+ max_price = filter[:max_price].presence || 'Infinity'- filter[:price] = [min_price, max_price].compact.join(',')- end+ filter[:price] = [min_price, max_price].compact.join(',')+ end- permitted_products_params.merge(- store: current_store,- filter: filter,- currency: current_currency- )+ permitted_products_params.merge(+ store: current_store,+ filter: filter,+ currency: current_currency+ )+ endenddef storefront_productsdiff --git a/storefront/app/helpers/spree/filters_helper.rb b/storefront/app/helpers/spree/filters_helper.rbindex 506553fd51..3a9c0533b7 100644--- a/storefront/app/helpers/spree/filters_helper.rb+++ b/storefront/app/helpers/spree/filters_helper.rb@@ -76,10 +76,14 @@ module Spreeif filter_selecteddefault_storefront_filter_values_scopeelse- Spree::OptionValue.for_products(storefront_products_for_filters).distinct+ all_option_values_scopeendend+ def all_option_values_scope+ @all_option_values_scope ||= Spree::OptionValue.for_products(storefront_products_scope).distinct+ end+def filter_values_for_filter(filter)selected = single_option_filter_selected?(filter.name)if filter.option_values.loaded?