optimize database queries by excluding bills field
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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<BillingLocation>("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<BillingLocation>("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
|
||||
|
||||
Reference in New Issue
Block a user