aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 04:55:00 +0100
committertv <tv@krebsco.de>2026-10-31 04:55:00 +0100
commitfd702346f09ad970ff068c04d1baa61c6a923357 (patch)
treecf76500b1f8fd59c8ac000a4390fe9a0736b987c /src/api
parent098c7ff677efd5015c97c2e5950ea5fb657af998 (diff)
dashboard: write growing list into page when serving
Diffstat (limited to 'src/api')
-rw-r--r--src/api/dashboard/dashboard.html6
-rw-r--r--src/api/dashboard/mod.rs13
2 files changed, 12 insertions, 7 deletions
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<AppState> {
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)
})
}