remove extra write on short window

This commit is contained in:
Alex Holliday committed 2026-09-24 13:49:54 -07:00
1 parent 187a0fc3d4
commit 4bbfe2e889
1 file changed
+3 -20
+3 -20
View File
@@ -188,25 +188,9 @@ export class StatusService implements IStatusService {
statusChanged = newStatus === "down"; statusChanged = newStatus === "down";
} }
// Not enough data points yet — record the check and return let thresholdBreaches: HardwareBreaches | undefined;
if (projectedWindow.length < monitor.statusWindowSize) {
const updated = await this.monitorsRepository.updateStatusWindowAndChecks(
monitor.id,
monitor.teamId,
check.status,
checkSnapshot,
monitor.statusWindowSize,
MAX_RECENT_CHECKS,
patch
);
return {
monitor: updated,
statusChanged,
prevStatus,
};
}
if (projectedWindow.length >= monitor.statusWindowSize) {
// First evaluate reachability status changes, which apply to all monitor types // First evaluate reachability status changes, which apply to all monitor types
// and take precedence over hardware breaches. // and take precedence over hardware breaches.
const reachabilityResult = this.computeReachability(newStatus, projectedWindow, monitor.statusWindowThreshold); const reachabilityResult = this.computeReachability(newStatus, projectedWindow, monitor.statusWindowThreshold);
@@ -216,7 +200,6 @@ export class StatusService implements IStatusService {
} }
// Evaluate hardware threshold breaches // Evaluate hardware threshold breaches
let thresholdBreaches: HardwareBreaches | undefined;
if (monitor.type === "hardware") { if (monitor.type === "hardware") {
const hardware = this.computeHardwareStatus({ const hardware = this.computeHardwareStatus({
currentStatus: newStatus, currentStatus: newStatus,
@@ -259,8 +242,8 @@ export class StatusService implements IStatusService {
statusChanged = true; statusChanged = true;
} }
} }
patch.status = newStatus; patch.status = newStatus;
}
// Single atomic write: push arrays + set status/counters // Single atomic write: push arrays + set status/counters
const updated = await this.monitorsRepository.updateStatusWindowAndChecks( const updated = await this.monitorsRepository.updateStatusWindowAndChecks(