From 116109c63dfaf504c8846e4a5c81c5c12d227b9d Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 23 Feb 2021 17:13:03 +0100 Subject: [PATCH] Make /api/orders N+1 free With the help of the bullet gem, and since we remove a couple of N+1s already, remove them all was just a few keystrokes away. This commits gets us from 42 SQL queries to 17, and 364.5ms to 253.9ms on my machine where I just have the sample data's orders. As usual, this will have a much bigger impact in scenarios with more data. --- app/services/search_orders.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/search_orders.rb b/app/services/search_orders.rb index ab261962bb..8e96cfbfa0 100644 --- a/app/services/search_orders.rb +++ b/app/services/search_orders.rb @@ -14,7 +14,7 @@ class SearchOrders def fetch_orders @search = search_query. - includes(:payments, :subscription). + includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle). ransack(params[:q]) return paginated_results if using_pagination?