Merge pull request #1481 from bluewave-labs/fix/be/db-indices

fix: be/db indices
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-12-31 17:38:29 -08:00
commit 350e560079
4 files changed
+21 -2

No files matched your search

+9 -2
View File
@@ -224,15 +224,22 @@ const getDateRange = (dateRange) => {
* @returns {Promise<Object>} All checks and date-ranged checks
*/
const getMonitorChecks = async (monitorId, model, dateRange, sortOrder) => {
const indexSpec = {
monitorId: 1,
createdAt: sortOrder, // This will be 1 or -1
};
const [checksAll, checksForDateRange] = await Promise.all([
model.find({ monitorId }).sort({ createdAt: sortOrder }),
model.find({ monitorId }).sort({ createdAt: sortOrder }).hint(indexSpec).lean(),
model
.find({
monitorId,
createdAt: { $gte: dateRange.start, $lte: dateRange.end },
})
.sort({ createdAt: sortOrder }),
.hint(indexSpec)
.lean(),
]);
return { checksAll, checksForDateRange };
};