From 2b857afeb12ea0f896589783b94252d9d05b9b57 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 13 Dec 2023 19:22:10 +0100 Subject: [PATCH] Avoid N+1 queries when fetching products in SolidusAdmin Co-Authored-By: Rainer Dema --- admin/app/controllers/solidus_admin/products_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/admin/app/controllers/solidus_admin/products_controller.rb b/admin/app/controllers/solidus_admin/products_controller.rb index 6e7ce79371f..29443ed7a64 100644 --- a/admin/app/controllers/solidus_admin/products_controller.rb +++ b/admin/app/controllers/solidus_admin/products_controller.rb @@ -13,11 +13,14 @@ class ProductsController < SolidusAdmin::BaseController def index products = apply_search_to( - Spree::Product.order(created_at: :desc, id: :desc), + Spree::Product.includes(:master, variants: :default_price), param: :q, ) - set_page_and_extract_portion_from(products) + set_page_and_extract_portion_from( + products, + ordered_by: { updated_at: :desc, id: :desc }, + ) respond_to do |format| format.html { render component('products/index').new(page: @page) }