fix(ui): сбрасывать снимок при изменении параметров speed-пробы

This commit is contained in:
Denozordec committed 2026-10-07 17:41:14 +07:00
1 parent 090206c893
commit 7f18fcb6db
11 files changed
+106 -22

No files matched your search

@@ -1,20 +1,21 @@
import { matchesSpeedProbeEndpoints, type SpeedProbeEndpoints } from "./speed-run-persistence.js"
import { sameSpeedMeasurement } from "@mmapp/contracts"
import type { SpeedProbeWrite } from "@mmapp/contracts"
export type SpeedProbePatch = SpeedProbeWrite & { sortOrder: number; updatedAt: string }
export type SpeedProbeTransaction = {
listProbes: () => Promise<SpeedProbeEndpoints[]>
listProbes: () => Promise<SpeedProbeWrite[]>
remove: (id: string) => Promise<void>
upsert: (row: SpeedProbePatch, createdAt: string, resetObservations: boolean) => Promise<void>
}
export type SpeedProbeStore = { transaction: (run: (tx: SpeedProbeTransaction) => Promise<void>) => Promise<void> }
/** The adapter must lock the catalog and commit all configuration changes atomically. Observations are preserved for the same pair and reset when its endpoints change. */
/** The adapter must lock the catalog and commit all configuration changes atomically. Observations are preserved only for the same measurement parameters. */
export async function replaceSpeedProbes(store: SpeedProbeStore, probes: SpeedProbeWrite[], now = new Date().toISOString()): Promise<void> {
await store.transaction(async tx => {
const nextIds = new Set(probes.map(row => row.id))
const previous = new Map((await tx.listProbes()).map(row => [row.id, row]))
for (const id of previous.keys()) if (!nextIds.has(id)) await tx.remove(id)
for (const [sortOrder, row] of probes.entries()) {
const reset = !matchesSpeedProbeEndpoints(previous.get(row.id), row)
const old = previous.get(row.id)
const reset = !old || !sameSpeedMeasurement(old, row)
await tx.upsert({ ...row, sortOrder, updatedAt: now }, now, reset)
}
})