optimization: projecting only what's needed
This commit is contained in:
@@ -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<BillingLocation>("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,7 +228,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
"yearMonth.month": { $gt: billMonth }
|
||||
}
|
||||
]
|
||||
}, { projection: { bills: 0 } })
|
||||
}, { projection: { _id: 1 } })
|
||||
.toArray();
|
||||
|
||||
// For each subsequent location, check if bill with same name already exists
|
||||
@@ -239,11 +239,8 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
_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
|
||||
@@ -371,8 +368,9 @@ export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID
|
||||
const location = await dbClient.collection<BillingLocation>("lokacije")
|
||||
.findOne({ _id: locationID, userId }, {
|
||||
projection: {
|
||||
"bills.attachment.fileContentsBase64": 0,
|
||||
"bills.barcodeImage": 0
|
||||
"name": 1,
|
||||
"bills._id": 1,
|
||||
"bills.name": 1
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user