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.

Improve lazy loading of associations in API v3

Damian Legawiec9c23edee160b
diff --git a/api/app/controllers/spree/api/v3/resource_controller.rb b/api/app/controllers/spree/api/v3/resource_controller.rb
index 63d125b4b6..0b0ace89f7 100644
--- a/api/app/controllers/spree/api/v3/resource_controller.rb
+++ b/api/app/controllers/spree/api/v3/resource_controller.rb
@@ -147,6 +147,7 @@ module Spree
end
base_scope = base_scope.accessible_by(current_ability, :show) unless @parent.present?
base_scope = base_scope.includes(scope_includes) if scope_includes.any?
+ base_scope = base_scope.preload_associations_lazily
model_class.include?(Spree::TranslatableResource) ? base_scope.i18n : base_scope
end
diff --git a/api/app/controllers/spree/api/v3/store/orders_controller.rb b/api/app/controllers/spree/api/v3/store/orders_controller.rb
index 192509ba6a..c0e26481bc 100644
--- a/api/app/controllers/spree/api/v3/store/orders_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders_controller.rb
@@ -77,7 +77,7 @@ module Spree
# Override scope to avoid accessible_by (Order permissions use blocks)
def scope
- current_store.orders.where(user: current_user)
+ current_store.orders.where(user: current_user).preload_associations_lazily
end
# Override set_resource to use friendly finder and order_token authorization
diff --git a/api/app/controllers/spree/api/v3/store/products_controller.rb b/api/app/controllers/spree/api/v3/store/products_controller.rb
index 41a7487fed..91d4b3f9f6 100644
--- a/api/app/controllers/spree/api/v3/store/products_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/products_controller.rb
@@ -32,7 +32,7 @@ module Spree
def scope_includes
[
master: [:prices, { stock_items: :stock_location }],
- variants: [:prices, { option_values: :option_type }, { stock_items: :stock_location }]
+ variants: [:prices, { stock_items: :stock_location }]
]
end
end