aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/dashboard/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/dashboard/mod.rs')
-rw-r--r--src/api/dashboard/mod.rs13
1 files changed, 9 insertions, 4 deletions
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)
})
}