From ccafdc44942beadabc770c79bf4c3b264ab012f0 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 24 Aug 2023 10:12:13 +1000 Subject: [PATCH] Remove redundant code bill_address is already joined in this query. The class variable isn't needed outside this scope. Arguably I think the condition on the select isn't needed; it wouldn't hurt to always select spree_addresses. But I'll try to avoid changing too much.. --- app/services/search_orders.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/services/search_orders.rb b/app/services/search_orders.rb index ce41bb036e..e9430b85ad 100644 --- a/app/services/search_orders.rb +++ b/app/services/search_orders.rb @@ -15,21 +15,19 @@ class SearchOrders attr_reader :params, :current_user def fetch_orders - @search = search_query. + search = search_query. includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle). - ransack(params[:q]) - - @search = @search.result(distinct: true) + ransack(params[:q]). + result(distinct: true) if ['bill_address', 'billing_address'].any?{ |param| params.dig(:q, :s)&.starts_with?(param) } - @search = @search.left_joins(:bill_address). - select('spree_addresses.*, spree_orders.*') + search = search.select('spree_addresses.*, spree_orders.*') end - @search + search end def search_query