Merge pull request #3126 from bluewave-labs/fix/checks-index
add index and cutof
This commit is contained in:
2 files changed
+7
No files matched your search
@@ -288,7 +288,9 @@ const CheckSchema = new Schema<CheckDocument>(
|
||||
CheckSchema.index({ updatedAt: 1 });
|
||||
CheckSchema.index({ "metadata.monitorId": 1, updatedAt: 1 });
|
||||
CheckSchema.index({ "metadata.monitorId": 1, updatedAt: -1 });
|
||||
CheckSchema.index({ "metadata.monitorId": 1, createdAt: -1 });
|
||||
CheckSchema.index({ "metadata.teamId": 1, updatedAt: -1 });
|
||||
CheckSchema.index({ "metadata.teamId": 1, createdAt: -1 });
|
||||
|
||||
const CheckModel = model<CheckDocument>("Check", CheckSchema);
|
||||
|
||||
|
||||
@@ -178,10 +178,15 @@ class MongoChecksRepistory implements IChecksRepository {
|
||||
}
|
||||
const mongoIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
||||
const limitPerMonitor = 25;
|
||||
const maxIntervalMs = Number(process.env.MONITOR_MAX_INTERVAL_MS ?? 10 * 60 * 1000);
|
||||
const bufferMs = Number(process.env.MONITOR_INTERVAL_BUFFER_MS ?? maxIntervalMs);
|
||||
const lookbackMs = 25 * maxIntervalMs + bufferMs;
|
||||
const cutoffDate = new Date(Date.now() - lookbackMs);
|
||||
const checkGroups = await CheckModel.aggregate([
|
||||
{
|
||||
$match: {
|
||||
"metadata.monitorId": { $in: mongoIds },
|
||||
createdAt: { $gte: cutoffDate },
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user