force index usage for getMonitorStatsById
This commit is contained in:
1 parent
bdf23a45b7
commit
0b5594f9c9
1 file changed
+9
-2
@@ -223,15 +223,22 @@ const getDateRange = (dateRange) => {
|
|||||||
* @returns {Promise<Object>} All checks and date-ranged checks
|
* @returns {Promise<Object>} All checks and date-ranged checks
|
||||||
*/
|
*/
|
||||||
const getMonitorChecks = async (monitorId, model, dateRange, sortOrder) => {
|
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([
|
const [checksAll, checksForDateRange] = await Promise.all([
|
||||||
model.find({ monitorId }).sort({ createdAt: sortOrder }),
|
model.find({ monitorId }).sort({ createdAt: sortOrder }).hint(indexSpec).lean(),
|
||||||
model
|
model
|
||||||
.find({
|
.find({
|
||||||
monitorId,
|
monitorId,
|
||||||
createdAt: { $gte: dateRange.start, $lte: dateRange.end },
|
createdAt: { $gte: dateRange.start, $lte: dateRange.end },
|
||||||
})
|
})
|
||||||
.sort({ createdAt: sortOrder }),
|
.hint(indexSpec)
|
||||||
|
.lean(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return { checksAll, checksForDateRange };
|
return { checksAll, checksForDateRange };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user