From 2e9bae0ea58410082dc9de2bb6abb00d34d089b3 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 26 Nov 2020 10:16:19 +0100 Subject: [PATCH] Move relation includes out of query object This query object is meant to be reusable but those includes are context-specific and will likely not be needed when reusing the query elsewhere. If we keep them there, chances are next dev might not notice it and will introduce a performance regression. --- app/controllers/admin/customers_controller.rb | 3 ++- app/services/customers_with_balance.rb | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/customers_controller.rb b/app/controllers/admin/customers_controller.rb index 630ffd361b..7a8598e268 100644 --- a/app/controllers/admin/customers_controller.rb +++ b/app/controllers/admin/customers_controller.rb @@ -65,7 +65,8 @@ module Admin def collection if json_request? && params[:enterprise_id].present? - CustomersWithBalance.new(managed_enterprise_id).query + CustomersWithBalance.new(managed_enterprise_id).query. + includes(:bill_address, :ship_address, user: :credit_cards) else Customer.where('1=0') end diff --git a/app/services/customers_with_balance.rb b/app/services/customers_with_balance.rb index 3cf667882a..12651ec14a 100644 --- a/app/services/customers_with_balance.rb +++ b/app/services/customers_with_balance.rb @@ -7,7 +7,6 @@ class CustomersWithBalance def query Customer.of(enterprise_id). - includes(:bill_address, :ship_address, user: :credit_cards). joins(left_join_non_cart_orders). group("customers.id"). select("customers.*").