From c77e4f781097d8ce9f2dbf9162fa71157f1efb96 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 04:55:00 +0100 Subject: dashboard: write growing list into page when serving --- src/api/dashboard/dashboard.html | 6 +++--- src/api/dashboard/mod.rs | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/api') diff --git a/src/api/dashboard/dashboard.html b/src/api/dashboard/dashboard.html index 091d7ee..dd764b6 100644 --- a/src/api/dashboard/dashboard.html +++ b/src/api/dashboard/dashboard.html @@ -162,9 +162,9 @@ const PAGE_VERSION = "__PAGE_VERSION__"; let state = null; let stateAt = 0; -// Fields that grow by themselves (`GROWING` and `is_age` in the node's dashboard). -const GROWING = new Set(["uptimeSecs", "dormantForSecs", "divergedForSecs", "observedSecs", - "lastFromNeighbourSecs", "oldestQuarantineSecs"]); +// Fields that grow by themselves: the node's list (`GROWING` and `is_age` in its +// dashboard), filled in when it serves the page. +const GROWING = new Set(__GROWING__); const isAge = key => key === "secsAgo" || key.endsWith("SecsAgo") || GROWING.has(key); const elapsed = () => Math.floor((Date.now() - stateAt) / 1000); const aged = (key, value) => diff --git a/src/api/dashboard/mod.rs b/src/api/dashboard/mod.rs index 0a15570..87f5aeb 100644 --- a/src/api/dashboard/mod.rs +++ b/src/api/dashboard/mod.rs @@ -321,8 +321,8 @@ fn links_json(links: &[Link]) -> JsonValue { .collect() } -/// Fields that grow by themselves besides those named `…SecsAgo` (the page knows -/// them too). +/// Fields that grow by themselves besides those named `…SecsAgo`; the page gets the +/// list when served (`GROWING_MARK`). const GROWING: &[&str] = &[ "uptimeSecs", "dormantForSecs", @@ -399,6 +399,8 @@ pub(crate) fn router(state: AppState) -> Router { const PAGE: &str = include_str!("dashboard.html"); /// Where the page says which version of it it is. const PAGE_VERSION_MARK: &str = "__PAGE_VERSION__"; +/// Where the page gets the age fields (`GROWING`), so the list is kept once. +const GROWING_MARK: &str = "__GROWING__"; /// The page's version (a hash of it), and the page saying so: a page whose version /// differs from the snapshot's `page` was served by another build, and reloads. @@ -406,12 +408,15 @@ fn page() -> &'static (String, String) { static PAGE_SERVED: OnceLock<(String, String)> = OnceLock::new(); PAGE_SERVED.get_or_init(|| { use sha2::{Digest, Sha256}; - let version: String = Sha256::digest(PAGE.as_bytes()) + let growing = serde_json::to_string(GROWING).unwrap_or_else(|_| "[]".to_owned()); + let page = PAGE.replace(GROWING_MARK, &growing); + // Of the page with its list: a new list is a new version too. + let version: String = Sha256::digest(page.as_bytes()) .iter() .take(8) .map(|byte| format!("{byte:02x}")) .collect(); - let served = PAGE.replace(PAGE_VERSION_MARK, &version); + let served = page.replace(PAGE_VERSION_MARK, &version); (version, served) }) } -- cgit v1.3.1