From 6d6a8782ab96c6eaaa8a496dd11d024655dd59c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 11 Aug 2025 11:50:47 +0200 Subject: [PATCH] optimize database queries by excluding bills field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added projections to exclude bills field from location lookup queries - Optimized updateOrAddLocation currentLocation query (line 79) - Optimized duplicate check query for subsequent months (line 201) - Optimized deleteLocationById location lookup query (line 372) - Reduces network traffic and memory usage by avoiding unnecessary bills data - Improves query performance especially for locations with many bills or large attachments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app/lib/actions/locationActions.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index baed3c9..057f757 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -76,7 +76,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat if(locationId) { // Get the current location first to find its name const currentLocation = await dbClient.collection("lokacije") - .findOne({ _id: locationId, userId }); + .findOne({ _id: locationId, userId }, { projection: { bills: 0 } }); if (!currentLocation) { return { @@ -198,7 +198,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat name: locationName, "yearMonth.year": monthData.year, "yearMonth.month": monthData.month - }); + }, { projection: { bills: 0 } }); // Only add if location with same name doesn't already exist in that month if (!existingLocation) { @@ -369,7 +369,7 @@ export const deleteLocationById = withUser(async (user:AuthenticatedUser, locati if (deleteInSubsequentMonths) { // Get the location name first to find all locations with the same name const location = await dbClient.collection("lokacije") - .findOne({ _id: locationID, userId }); + .findOne({ _id: locationID, userId }, { projection: { bills: 0 } }); if (location) { // Delete all locations with the same name in current and subsequent months