Fix work recovery and reduce engine and chart overhead
Docs / docs (push) Successful in 33s
Playwright Tests / test-playwright (1, 2) (push) Failing after 1m37s
Playwright Tests / test-playwright (2, 2) (push) Failing after 27s
pre-commit / pre-commit (push) Failing after 2m37s
Test Backend / test-backend (3.12) (push) Successful in 5m7s
Test Backend / test-backend (3.14) (push) Successful in 5m2s
Compose Smoke Test / test-compose (push) Failing after 28s
Playwright Tests / merge-reports (push) Failing after 2m29s
Docs / docs (push) Successful in 33s
Playwright Tests / test-playwright (1, 2) (push) Failing after 1m37s
Playwright Tests / test-playwright (2, 2) (push) Failing after 27s
pre-commit / pre-commit (push) Failing after 2m37s
Test Backend / test-backend (3.12) (push) Successful in 5m7s
Test Backend / test-backend (3.14) (push) Successful in 5m2s
Compose Smoke Test / test-compose (push) Failing after 28s
Playwright Tests / merge-reports (push) Failing after 2m29s
This commit is contained in:
@@ -8,7 +8,11 @@ import {
|
||||
type Range,
|
||||
} from "@/components/Common/RangePicker"
|
||||
import { MAX_SERIES, UplotChart } from "@/components/Common/UplotChart"
|
||||
import { useLiveValue, useLiveValues } from "@/components/Flow/liveStore"
|
||||
import {
|
||||
type LiveValue,
|
||||
useLiveValue,
|
||||
useLiveValues,
|
||||
} from "@/components/Flow/liveStore"
|
||||
import {
|
||||
compareQueryOptions,
|
||||
NO_CURVE,
|
||||
@@ -91,6 +95,36 @@ function merge(fetched: HistoryPoint[], tail: HistoryPoint[], cap: number) {
|
||||
return [...fetched, ...tail.filter((point) => point.ts > since)].slice(-cap)
|
||||
}
|
||||
|
||||
/** Advance the bounded live tails without scheduling a stale chart commit. */
|
||||
export function chartTails(
|
||||
previous: Record<string, HistoryPoint[]>,
|
||||
names: string[],
|
||||
live: (LiveValue | undefined)[],
|
||||
cap: number,
|
||||
): Record<string, HistoryPoint[]> {
|
||||
const next: Record<string, HistoryPoint[]> = {}
|
||||
let changed = false
|
||||
names.forEach((name, index) => {
|
||||
const kept = previous[name] ?? []
|
||||
const point = live[index]
|
||||
const last = kept[kept.length - 1]
|
||||
let tail = kept
|
||||
if (typeof point?.value === "number" && point.ts) {
|
||||
if (last?.ts !== point.ts) {
|
||||
tail = [...kept, { ts: point.ts, value: point.value }]
|
||||
} else if (!Object.is(last.value, point.value)) {
|
||||
tail = [...kept.slice(0, -1), { ts: point.ts, value: point.value }]
|
||||
}
|
||||
}
|
||||
if (tail.length > cap) tail = tail.slice(-cap)
|
||||
next[name] = tail
|
||||
if (tail !== previous[name]) changed = true
|
||||
})
|
||||
return changed || Object.keys(previous).length !== Object.keys(next).length
|
||||
? next
|
||||
: previous
|
||||
}
|
||||
|
||||
/**
|
||||
* A chart, drawn from whichever source it was pointed at.
|
||||
*
|
||||
@@ -275,34 +309,10 @@ function LiveChart({ widget }: WidgetProps) {
|
||||
// What arrived over the socket since the history was fetched. Appending beats
|
||||
// refetching the whole series every time a value lands.
|
||||
const [tails, setTails] = useState<Record<string, HistoryPoint[]>>({})
|
||||
const key = names.join(" ")
|
||||
const stamps = live.map((value) => value?.ts ?? 0).join(",")
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: the timestamps are what makes a tail longer; `live` is a fresh array every render.
|
||||
useEffect(() => {
|
||||
setTails((previous) => {
|
||||
const next: Record<string, HistoryPoint[]> = {}
|
||||
let changed = false
|
||||
names.forEach((name, index) => {
|
||||
const point = live[index]
|
||||
const kept = previous[name] ?? []
|
||||
const ts = point?.ts
|
||||
if (
|
||||
typeof point?.value !== "number" ||
|
||||
!ts ||
|
||||
kept[kept.length - 1]?.ts === ts
|
||||
) {
|
||||
next[name] = kept
|
||||
return
|
||||
}
|
||||
next[name] = [...kept, { ts, value: point.value }].slice(-cap)
|
||||
changed = true
|
||||
})
|
||||
// Dropping a series is a change too, even without a new reading.
|
||||
return changed || Object.keys(previous).length !== names.length
|
||||
? next
|
||||
: previous
|
||||
})
|
||||
}, [key, stamps, cap])
|
||||
const nextTails = chartTails(tails, names, live, cap)
|
||||
// React retries this component before rendering its children. An effect
|
||||
// would commit the old chart first, then render and draw it a second time.
|
||||
if (nextTails !== tails) setTails(nextTails)
|
||||
|
||||
const plots = names.map((name, index) =>
|
||||
merge(
|
||||
|
||||
Reference in New Issue
Block a user