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 ar_lazy_preload selectively

Damian Legawiecd3a3a43717c1
diff --git a/api/app/controllers/spree/api/v3/resource_controller.rb b/api/app/controllers/spree/api/v3/resource_controller.rb
index 1c18eb9ebf..f8d2599134 100644
--- a/api/app/controllers/spree/api/v3/resource_controller.rb
+++ b/api/app/controllers/spree/api/v3/resource_controller.rb
@@ -74,12 +74,18 @@ module Spree
def collection
return @collection if @collection.present?
- @search = scope.ransack(ransack_params)
+ @search = scope.includes(collection_includes).
+ preload_associations_lazily.
+ ransack(ransack_params)
result = @search.result(distinct: true)
@pagy, @collection = pagy(result, limit: limit, page: page)
@collection
end
+ def collection_includes
+ []
+ end
+
# Ransack query parameters
def ransack_params
params[:q] || {}
diff --git a/api/config/initializers/ar_lazy_preload.rb b/api/config/initializers/ar_lazy_preload.rb
deleted file mode 100644
index f271667b4f..0000000000
--- a/api/config/initializers/ar_lazy_preload.rb
+++ /dev/null
@@ -1 +0,0 @@
-ArLazyPreload.config.auto_preload = true