From 38c327dae032c8a2a5113cb1abe2240038992bc9 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 29 Nov 2019 17:10:23 +0100 Subject: [PATCH] Improve N+1 issues around #suppliers_of_products_distributed_by There's still some real mess here with repeating queries, but resolving it is out of scope for this quick PR --- app/controllers/spree/admin/reports_controller_decorator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 3a7f5217fc..1a21606017 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -222,7 +222,8 @@ Spree::Admin::ReportsController.class_eval do end def suppliers_of_products_distributed_by(distributors) - distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq + distributors.map { |d| Spree::Product.in_distributor(d).includes(:supplier).all }. + flatten.map(&:supplier).uniq end # Load order cycles the current user has access to