date limit
This commit is contained in:
1 parent
4119189c71
commit
4f3f5408ef
1 file changed
+8
-4
@@ -334,10 +334,13 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const limitPerMonitor = options?.limitPerMonitor ?? 25;
|
const limitPerMonitor = options?.limitPerMonitor ?? 25;
|
||||||
|
const dateFilter = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
monitorIds.map(async (monitorId) => {
|
monitorIds.map(async (monitorId) => {
|
||||||
const docs = await CheckModel.find({ "metadata.monitorId": new mongoose.Types.ObjectId(monitorId) })
|
const docs = await CheckModel.find({
|
||||||
|
"metadata.monitorId": new mongoose.Types.ObjectId(monitorId),
|
||||||
|
createdAt: { $gte: dateFilter },
|
||||||
|
})
|
||||||
.sort({ createdAt: -1 })
|
.sort({ createdAt: -1 })
|
||||||
.limit(limitPerMonitor)
|
.limit(limitPerMonitor)
|
||||||
.lean();
|
.lean();
|
||||||
@@ -345,10 +348,11 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
return results.reduce<LatestChecksMap>((acc, { monitorId, docs }) => {
|
const mapped = results.reduce<LatestChecksMap>((acc, { monitorId, docs }) => {
|
||||||
acc[monitorId] = docs.map((doc) => this.toEntity(doc as CheckDocument));
|
acc[monitorId] = docs.map((doc: any) => this.toEntity(doc as CheckDocument));
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
return mapped;
|
||||||
};
|
};
|
||||||
|
|
||||||
findByDateRangeAndMonitorId = async (monitorId: string, startDate: Date, endDate: Date, dateString: string, options?: { type?: MonitorType }) => {
|
findByDateRangeAndMonitorId = async (monitorId: string, startDate: Date, endDate: Date, dateString: string, options?: { type?: MonitorType }) => {
|
||||||
|
|||||||
Reference in new issue
Block a user