From 237ebd6ec4a93e8319139dc8df9092612f1ef76b Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Sat, 8 May 2021 21:09:06 +0530 Subject: [PATCH] Removed N+1 queries while counting line_items --- app/serializers/api/order_serializer.rb | 2 +- app/views/spree/users/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb index f741675318..740d8a9fb2 100644 --- a/app/serializers/api/order_serializer.rb +++ b/app/serializers/api/order_serializer.rb @@ -22,7 +22,7 @@ module Api end def item_count - object.line_items.sum(:quantity) + object.line_items.size end def completed_at diff --git a/app/views/spree/users/show.html.haml b/app/views/spree/users/show.html.haml index 6fa0d875e2..c85ae06d75 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -1,5 +1,5 @@ - content_for :injection_data do - = inject_json_array("orders", @orders.all, Api::OrderSerializer) + = inject_json_array("orders", @orders.all.includes(:line_items), Api::OrderSerializer) = inject_json_array("shops", @shops.all, Api::ShopForOrdersSerializer) = inject_saved_credit_cards