From ea9d81a8d1cba29d88a844fdb77f3475998350a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CApoorv?= <“tiwari.apoorv1316@gmail.com”> Date: Fri, 8 Mar 2024 16:44:02 +0530 Subject: [PATCH] fix N+1 query --- .../internal_api/v1/expenses/expenses_summary_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/internal_api/v1/expenses/expenses_summary_controller.rb b/app/controllers/internal_api/v1/expenses/expenses_summary_controller.rb index 83ac2e4f81..8a9a92c57b 100644 --- a/app/controllers/internal_api/v1/expenses/expenses_summary_controller.rb +++ b/app/controllers/internal_api/v1/expenses/expenses_summary_controller.rb @@ -20,11 +20,13 @@ def total_expenses_sum end def default_category_expenses - Expense.where(expense_category: ExpenseCategory.default_categories, company_id: current_company.id) + Expense.includes(:expense_category).where( + expense_category: ExpenseCategory.default_categories, + company_id: current_company.id) end def company_expenses_categories - Expense.where(expense_category: current_company.expense_categories) + Expense.includes(:expense_category).where(expense_category: current_company.expense_categories) end def formatted_expenses_sum(expenses)