snapshots
This commit is contained in:
1 parent
665eb9a67f
commit
4ad09fad4f
3 files changed
+23
-8
No files matched your search
@@ -2,7 +2,7 @@ import type { Check, MonitorType } from "@/types/index.js";
|
||||
import type { LatestChecksMap } from "@/repositories/checks/MongoChecksRepistory.js";
|
||||
|
||||
export interface IChecksRepository {
|
||||
findLatestChecksByMonitorIds(monitorIds: string[]): Promise<LatestChecksMap>;
|
||||
findLatestChecksByMonitorIds(monitorIds: string[], options?: { limitPerMonitor?: number }): Promise<LatestChecksMap>;
|
||||
findDateRangeChecksByMonitor(
|
||||
monitorId: string,
|
||||
startDate: Date,
|
||||
|
||||
@@ -177,15 +177,18 @@ class MongoChecksRepistory implements IChecksRepository {
|
||||
};
|
||||
};
|
||||
|
||||
findLatestChecksByMonitorIds = async (monitorIds: string[]): Promise<LatestChecksMap> => {
|
||||
findLatestChecksByMonitorIds = async (
|
||||
monitorIds: string[],
|
||||
options?: { limitPerMonitor?: number }
|
||||
): Promise<LatestChecksMap> => {
|
||||
if (monitorIds.length === 0) {
|
||||
return {};
|
||||
}
|
||||
const mongoIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
||||
const limitPerMonitor = 25;
|
||||
const limitPerMonitor = options?.limitPerMonitor ?? 25;
|
||||
const maxIntervalMs = Number(10 * 60 * 1000);
|
||||
const bufferMs = Number(maxIntervalMs);
|
||||
const lookbackMs = 25 * maxIntervalMs + bufferMs;
|
||||
const lookbackMs = limitPerMonitor * maxIntervalMs + bufferMs;
|
||||
const cutoffDate = new Date(Date.now() - lookbackMs);
|
||||
const checkGroups = await CheckModel.aggregate([
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user