force index usage for getMonitorStatsById

This commit is contained in:
Alex Holliday
2024-12-28 09:37:00 -08:00
parent bdf23a45b7
commit 0b5594f9c9
+9 -2
View File
@@ -223,15 +223,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 };
};