From 6f9fefddd2e903221a609014a98b68fa3be219e2 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 27 Jan 2026 19:24:02 +0000 Subject: [PATCH] recent checks --- server/src/controllers/monitorController.ts | 1 - server/src/controllers/statusPageController.ts | 3 +-- .../src/repositories/monitors/IMonitorsRepository.ts | 4 ++-- .../repositories/monitors/MongoMonitorsRepository.ts | 7 +++---- server/src/service/business/monitorService.ts | 11 +++-------- server/src/types/check.ts | 2 ++ server/src/types/monitor.ts | 10 +++------- 7 files changed, 14 insertions(+), 24 deletions(-) diff --git a/server/src/controllers/monitorController.ts b/server/src/controllers/monitorController.ts index 30ceabbc5..721565f59 100644 --- a/server/src/controllers/monitorController.ts +++ b/server/src/controllers/monitorController.ts @@ -324,7 +324,6 @@ class MonitorController { try { await getMonitorsByTeamIdParamValidation.validateAsync(req.params); await getMonitorsWithChecksQueryValidation.validateAsync(req.query); - const explain = optionalBoolean(req?.query?.explain, "explain"); const limit = optionalNumber(req?.query?.limit, "limit"); const page = optionalNumber(req?.query?.page, "page"); diff --git a/server/src/controllers/statusPageController.ts b/server/src/controllers/statusPageController.ts index 3501a6592..866dd715a 100644 --- a/server/src/controllers/statusPageController.ts +++ b/server/src/controllers/statusPageController.ts @@ -7,7 +7,6 @@ import { IStatusPageService } from "@/service/business/statusPageService.js"; import { IMonitorsRepository } from "@/repositories/index.js"; import { ISettingsService } from "@/service/system/settingsService.js"; import { ParseBoolean } from "@/utils/utils.js"; -import { MonitorWithChecks } from "@/types/index.js"; import { NormalizeData } from "@/utils/dataUtils.js"; const SERVICE_NAME = "statusPageController"; @@ -84,7 +83,7 @@ class StatusPageController { const monitors = await this.monitorsRepository.findByIdsWithChecks(statusPage.monitors); const normalizedMonitors = monitors.map((monitor) => { - const normalizedChecks = NormalizeData(monitor.checks, 10, 100); + const normalizedChecks = NormalizeData(monitor.recentChecks, 10, 100); if (!showURL) { const { url, port, secret, notifications, ...rest } = monitor; return { ...rest, checks: normalizedChecks }; diff --git a/server/src/repositories/monitors/IMonitorsRepository.ts b/server/src/repositories/monitors/IMonitorsRepository.ts index 072772e9e..2fbce3406 100644 --- a/server/src/repositories/monitors/IMonitorsRepository.ts +++ b/server/src/repositories/monitors/IMonitorsRepository.ts @@ -1,4 +1,4 @@ -import { type MonitorType, type Monitor, type MonitorsSummary, type MonitorWithChecks } from "@/types/index.js"; +import { type MonitorType, type Monitor, type MonitorsSummary } from "@/types/index.js"; export interface TeamQueryConfig { limit?: number; @@ -25,7 +25,7 @@ export interface IMonitorsRepository { findAll(): Promise; findByTeamId(teamId: string, config: TeamQueryConfig): Promise; findByIds(monitorIds: string[]): Promise; - findByIdsWithChecks(monitorIds: string[], checksCount?: number): Promise; + findByIdsWithChecks(monitorIds: string[], checksCount?: number): Promise; // update updateById(monitorId: string, teamId: string, updates: Partial): Promise; diff --git a/server/src/repositories/monitors/MongoMonitorsRepository.ts b/server/src/repositories/monitors/MongoMonitorsRepository.ts index e27fd4632..9cb519303 100644 --- a/server/src/repositories/monitors/MongoMonitorsRepository.ts +++ b/server/src/repositories/monitors/MongoMonitorsRepository.ts @@ -1,6 +1,6 @@ import { MonitorModel } from "@/db/models/index.js"; import type { MonitorDocument, CheckSnapshotDocument } from "@/db/models/index.js"; -import type { Monitor, MonitorsSummary, MonitorWithChecks, CheckSnapshot, Check } from "@/types/index.js"; +import type { Monitor, MonitorsSummary, CheckSnapshot, Check } from "@/types/index.js"; import mongoose, { type FilterQuery, type PipelineStage } from "mongoose"; import type { IMonitorsRepository, TeamQueryConfig, SummaryConfig } from "./IMonitorsRepository.js"; import { AppError } from "@/utils/AppError.js"; @@ -79,7 +79,7 @@ class MongoMonitorsRepository implements IMonitorsRepository { return this.mapDocuments(monitors); }; - findByIdsWithChecks = async (monitorIds: string[], checksCount: number = 25): Promise => { + findByIdsWithChecks = async (monitorIds: string[], checksCount: number = 25): Promise => { if (!monitorIds.length) { return []; } @@ -315,7 +315,7 @@ class MongoMonitorsRepository implements IMonitorsRepository { }; }; - private toEntityWithChecks = (doc: any): MonitorWithChecks => { + private toEntityWithChecks = (doc: any): Monitor => { const toStringId = (value: unknown): string => { if (value instanceof mongoose.Types.ObjectId) { return value.toString(); @@ -396,7 +396,6 @@ class MongoMonitorsRepository implements IMonitorsRepository { recentChecks: (doc.recentChecks ?? []).map((check: any) => this.toCheckSnapshot(check)), createdAt: toDateString(doc.createdAt), updatedAt: toDateString(doc.updatedAt), - checks, }; }; diff --git a/server/src/service/business/monitorService.ts b/server/src/service/business/monitorService.ts index 90a909991..b950c9a32 100644 --- a/server/src/service/business/monitorService.ts +++ b/server/src/service/business/monitorService.ts @@ -363,15 +363,10 @@ export class MonitorService implements IMonitorService { const monitorsWithChecks = monitorsList.map((monitor: Monitor) => { const rawChecks = monitor.recentChecks ?? []; const isSnapshotType = snapshotOnlyRequest || snapshotTypes.includes(monitor.type); - // recentChecks are stored oldest-first, reverse to get newest-first for display - const reversedChecks = [...rawChecks].reverse(); - const checks = isSnapshotType ? reversedChecks.slice(0, 1) : NormalizeData(reversedChecks, 10, 100); - return { - ...monitor, - checks, - }; + const checks = isSnapshotType ? rawChecks.slice(0, 1) : NormalizeData(rawChecks, 10, 100); + monitor.recentChecks = checks; + return monitor; }); - return { summary: summary ?? null, count, monitors: monitorsWithChecks }; }; diff --git a/server/src/types/check.ts b/server/src/types/check.ts index 6d38d538f..a2c377f54 100644 --- a/server/src/types/check.ts +++ b/server/src/types/check.ts @@ -189,3 +189,5 @@ export type NormalizedCheck = T & { export type NormalizedUptimeCheck = T & { originalAvgResponseTime: number; }; + +export type CheckSnapshot = Omit; diff --git a/server/src/types/monitor.ts b/server/src/types/monitor.ts index 96cd44a65..cdbdb7c83 100644 --- a/server/src/types/monitor.ts +++ b/server/src/types/monitor.ts @@ -1,6 +1,6 @@ import type { Check } from "@/types/check.js"; - -export type CheckSnapshot = Omit; +import type { CheckSnapshot } from "@/types/check.js"; +export type { CheckSnapshot } from "@/types/check.js"; export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "unknown"] as const; export type MonitorType = (typeof MonitorTypes)[number]; @@ -57,14 +57,10 @@ export interface MonitorsSummary { pausedMonitors: number; } -export interface MonitorWithChecks extends Monitor { - checks: Check[] | CheckSnapshot[]; -} - export interface MonitorsWithChecksByTeamIdResult { summary: MonitorsSummary | null; count: number; - monitors: MonitorWithChecks[]; + monitors: Monitor[]; } export interface UptimeDetailsResult {