Faster first load; demo date tags stay current

First load:
- Draw the Overview as soon as the data arrives instead of on its next
  2-second timer tick (about 2.5 s to 0.6 s on a typical connection).
- Start on DOMContentLoaded instead of window.onload.
- Load the ~900 KB PDF library only when someone exports a PDF.
- Fetch the startup files side by side, and build the docs search index
  after the dashboard has drawn (unless the visit starts on /docs).
- Show a loading placeholder on the Overview until the data arrives.

Demo: the date-batch tags sit on fixed working-day offsets from today.
The seed records them in Demo-Dates.json and the worker relabels them when
the day changes, so a long-running container never looks stale.
This commit is contained in:
Johan Sandoval committed 2026-10-07 20:22:09 +00:00
1 parent 5e8dea8027
commit 9731368687
8 files changed
+105 -21

No files matched your search

+36
View File
@@ -135,6 +135,42 @@ function Get-DemoPick([string]$name, [string]$salt, [array]$list) { return $list
function Get-DemoInt([string]$name, [string]$salt, [int]$min, [int]$max) { return $min + [int][math]::Floor((Get-DemoRand $name $salt) * ($max - $min + 1)) }
function Get-DemoNow { return [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() }
# -----------------------------------------------------------------------------------------
# Date-batch tags ("M/d") sit on fixed working-day offsets from today. The seed records the
# labels it used in Demo-Dates.json and the worker moves them along when the day changes, so
# a demo container that runs for weeks still shows this week's deployments.
# -----------------------------------------------------------------------------------------
$script:DemoDateOffsets = @(-4, -3, -2, -1, 0, 1)
function Get-DemoWorkday([datetime]$from, [int]$offset) {
$d = $from.Date; $step = [math]::Sign($offset); $left = [math]::Abs($offset)
while ($left -gt 0) { $d = $d.AddDays($step); if ($d.DayOfWeek -ne 'Saturday' -and $d.DayOfWeek -ne 'Sunday') { $left-- } }
return $d
}
function Get-DemoDateTags { $today = Get-Date; return @($script:DemoDateOffsets | ForEach-Object { (Get-DemoWorkday $today $_).ToString("M/d") }) }
function Update-DemoDateTags([string]$DataDir) {
$metaPath = Join-Path $DataDir "Demo-Dates.json"
$trackedPath = Join-Path $DataDir "Tracked-Devices.json"
if (-not (Test-Path $metaPath) -or -not (Test-Path $trackedPath)) { return }
try { $old = @(([System.IO.File]::ReadAllText($metaPath) | ConvertFrom-Json).Tags) } catch { return }
$new = Get-DemoDateTags
if ($old.Count -ne $new.Count -or ($old -join '|') -eq ($new -join '|')) { return }
$rename = @{}
for ($i = 0; $i -lt $old.Count; $i++) { $rename[$old[$i]] = $new[$i] }
try { $tracked = [System.IO.File]::ReadAllText($trackedPath) | ConvertFrom-Json } catch { return }
$out = [ordered]@{}
foreach ($prop in $tracked.PSObject.Properties) {
$name = if ($rename.ContainsKey($prop.Name)) { $rename[$prop.Name] } else { $prop.Name }
$out[$name] = $prop.Value
}
$tmp = "$trackedPath.tmp"
[System.IO.File]::WriteAllText($tmp, ($out | ConvertTo-Json -Depth 5), [System.Text.Encoding]::UTF8)
Move-Item -LiteralPath $tmp -Destination $trackedPath -Force
[System.IO.File]::WriteAllText($metaPath, (@{ Tags = $new } | ConvertTo-Json), [System.Text.Encoding]::UTF8)
Write-Host "Demo: date tags moved to today ($($old -join ', ') -> $($new -join ', '))" -ForegroundColor DarkCyan
}
# -----------------------------------------------------------------------------------------
# Serial scheme: 7 chars + check char. Sources and destinations use different check offsets
# and a destination's first 7 chars are a reversible scramble of its source's.