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.

Use more lazy preload in storefront

Damian Legawiece6843dbd6df3
diff --git a/storefront/app/controllers/spree/products_controller.rb b/storefront/app/controllers/spree/products_controller.rb
index 7d102fc9f5..d96dc87cb9 100644
--- a/storefront/app/controllers/spree/products_controller.rb
+++ b/storefront/app/controllers/spree/products_controller.rb
@@ -25,6 +25,7 @@ module Spree
# when using not default locale, our related products are different for different locales.
@products = storefront_products_scope.where.not(id: @product.id).
multi_search(@product.name).includes(storefront_products_includes).
+ preload_associations_lazily.
limit(@section.preferred_max_products_to_show)
end
diff --git a/storefront/app/controllers/spree/search_controller.rb b/storefront/app/controllers/spree/search_controller.rb
index 8f6923bf1c..7a99bd2eb2 100644
--- a/storefront/app/controllers/spree/search_controller.rb
+++ b/storefront/app/controllers/spree/search_controller.rb
@@ -14,7 +14,7 @@ module Spree
if query.present? && query.length >= Spree::Storefront::Config.search_min_query_length
products_scope = storefront_products_scope.multi_search(query)
- @products = products_scope.includes(storefront_products_includes)
+ @products = products_scope.includes(storefront_products_includes).preload_associations_lazily
@taxons = current_store.taxons.search_by_name(query)
end
end
diff --git a/storefront/app/helpers/spree/taxons_helper.rb b/storefront/app/helpers/spree/taxons_helper.rb
index 2d9139d348..b6c6397a6f 100644
--- a/storefront/app/helpers/spree/taxons_helper.rb
+++ b/storefront/app/helpers/spree/taxons_helper.rb
@@ -12,7 +12,9 @@ module Spree
sort_by: 'default'
}
- storefront_products_finder.new(scope: current_store.products.includes(storefront_products_includes), params: finder_params).execute
+ scope = current_store.products.includes(storefront_products_includes).preload_associations_lazily
+
+ storefront_products_finder.new(scope: scope, params: finder_params).execute
end
end
end