From 21da2f0d49909d29faa58e28707d08a6189dae09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 11 Aug 2025 13:38:59 +0200 Subject: [PATCH 1/4] optimization: projecting only what's needed --- app/lib/actions/billActions.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/lib/actions/billActions.ts b/app/lib/actions/billActions.ts index f618d7b..c3feb47 100644 --- a/app/lib/actions/billActions.ts +++ b/app/lib/actions/billActions.ts @@ -213,7 +213,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI if (addToSubsequentMonths && billYear && billMonth) { // Get the current location to find its name const currentLocation = await dbClient.collection("lokacije") - .findOne({ _id: locationId, userId }, { projection: { bills: 0 } }); + .findOne({ _id: locationId, userId }, { projection: { name: 1 } }); if (currentLocation) { // Find all subsequent months that have the same location name @@ -228,8 +228,8 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI "yearMonth.month": { $gt: billMonth } } ] - }, { projection: { bills: 0 } }) - .toArray(); + }, { projection: { _id: 1 } }) + .toArray(); // For each subsequent location, check if bill with same name already exists const updateOperations = []; @@ -238,12 +238,9 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI .findOne({ _id: location._id, "bills.name": billName - }, { - projection: { - "bills.$": 1, - "bills.attachment": 0, - "bills.barcodeImage": 0 - } + }, { + // We only need to know if a matching bill exists; avoid conflicting projections + projection: { _id: 1 } }); // Only add if bill with same name doesn't already exist @@ -370,9 +367,10 @@ export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID // Get the current location and bill to find the bill name and location name const location = await dbClient.collection("lokacije") .findOne({ _id: locationID, userId }, { - projection: { - "bills.attachment.fileContentsBase64": 0, - "bills.barcodeImage": 0 + projection: { + "name": 1, + "bills._id": 1, + "bills.name": 1 } }); From aab0afd045a8f116cc2c10d71319eccc70824c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 11 Aug 2025 13:57:07 +0200 Subject: [PATCH 2/4] locationAction: fixed optional form fields --- app/lib/actions/locationActions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 057f757..6414d44 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -27,8 +27,8 @@ const FormSchema = (t:IntlTemplateFn) => z.object({ _id: z.string(), locationName: z.coerce.string().min(1, t("location-name-required")), locationNotes: z.string(), - addToSubsequentMonths: z.boolean().optional(), - updateScope: z.enum(["current", "subsequent", "all"]).optional(), + addToSubsequentMonths: z.boolean().optional().nullable(), + updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(), }) // dont include the _id field in the response .omit({ _id: true }); From fade52a49f72bad236720910af380bcb27f05f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 11 Aug 2025 13:57:36 +0200 Subject: [PATCH 3/4] billActions: projection optimization --- app/lib/actions/billActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/actions/billActions.ts b/app/lib/actions/billActions.ts index c3feb47..89a22fb 100644 --- a/app/lib/actions/billActions.ts +++ b/app/lib/actions/billActions.ts @@ -391,7 +391,7 @@ export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID } ], "bills.name": bill.name - }, { projection: { bills: 0 } }) + }, { projection: { _id: 1 } }) .toArray(); // Delete the bill from all subsequent locations (by name) From daa9b2a134400cdaec008012ccc6c142208b5b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 11 Aug 2025 13:58:57 +0200 Subject: [PATCH 4/4] locationAction: query optimization --- app/lib/actions/locationActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 6414d44..7accab4 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -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 }, { projection: { bills: 0 } }); + .findOne({ _id: locationID, userId }, { projection: { name: 1 } }); if (location) { // Delete all locations with the same name in current and subsequent months