Skip to content

Commit 389218d

Browse files
perf(solidus_admin): Reduce N+1 queries for order index
There was a N+1 query in order index view. For each row the quantity of the line items was fetched. It is now included and reduces the amount of SQL queries. This change reduced the loading time of 8M orders from 836ms to 520ms.
1 parent 2dc22af commit 389218d

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

admin/app/components/solidus_admin/orders/index/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def items_column
162162
{
163163
header: :items,
164164
data: ->(order) do
165-
content_tag :div, t(".columns.items", count: order.line_items.sum(:quantity))
165+
content_tag :div, t(".columns.items", count: order.line_items.sum(&:quantity))
166166
end
167167
}
168168
end

admin/app/controllers/solidus_admin/orders_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class OrdersController < SolidusAdmin::BaseController
1313

1414
def index
1515
orders = apply_search_to(
16-
Spree::Order,
16+
Spree::Order.includes(:line_items),
1717
param: :q,
1818
distinct: false
1919
)

0 commit comments

Comments
 (0)