Public: anyone can read this; the crew can change it.

Home reuses its last KPI, panel and vitals answer for 60 s, whatever is written since #7692

Parked opened this
Closed without merging

Home now reuses its KPI, pinned-panel and vitals answers for 60 s from when they were computed, even when the forge writes in between. Before, these caches were keyed on writeStamp(db), which changes every second, so they never hit (part of #7494, the slow home page).

Notes

stopped parked by the crew

opened this

Home now reuses its KPI, pinned-panel and vitals answers for 60 s from when they were computed, even when the forge writes in between. Before, these caches were keyed on writeStamp(db), which changes every second, so they never hit (part of #7494, the slow home page).

What changed

  • src/web/studio/home_cache.ts: cachedKpis, cachedPanel and cachedVitals are now keyed only on what they answer for (the KPI key is UTC hour, ceiling and data directory; a panel's key is its board slug and its definition). Nothing is cached inside an open transaction, because those rows may roll back.
    • New HOME_TTL_MS = 60_000.
    • A test-only clock, setHomeClock.
    • cachedKpis and cachedVitals take an optional compute argument for tests.
  • cachedWaiting is unchanged: it still misses on any write and lasts 30 s at most, so the asks count stays exact.
  • test/home-cache-ttl.test.ts (new): cachedKpis runs compute once across 50 writes, still once at 59 s, and again at 61 s on the injected clock. Panels (each kept under its own key) and vitals behave the same. Nothing is kept inside a transaction, and the waiting line still misses after a write. The gate takes every test/*.test.ts by default, so this file runs without being listed.
  • docs/CACHING.md: one passage on the 60 s rule.

Two existing tests changed because their old expectation is what this issue reverses:

  • test/home-cache.test.ts: the first test expected a write to cause a miss. It now expects a hit after the write.
  • test/observability-budget.test.ts ("a cold home answers within a few passes over the runs"): it used a write to make home cold. It now also clears the KPI, panel and vitals caches to get the cold view; the time budget it checks is the same.

Not done: readKpis itself, migrations, and the stale-refresh path (the next issue). A figure on the owner's home can now be up to 60 s old.

Checks: bun x tsc --noEmit is clean. scripts/fast.ts named 908 test files, too many to run here, so I ran the home, KPI, vitals, pins, studio, caching-doc and observability-budget tests: all pass.

To try it, open / as the owner twice within a minute while the forge is busy. The second response's server-timing shows kpis and panels with desc="hit".

🤖 Generated with Claude Code

Closes #7624

2 earlier comments
commented

Home now reuses its KPI, pinned-panel and vitals answers for 60 s from when they were computed, even when the forge writes in between. Before, these caches were keyed on writeStamp(db), which changes every second, so they never hit (part of #7494, the slow home page).

What changed

  • src/web/studio/home_cache.ts: cachedKpis, cachedPanel and cachedVitals are now keyed only on what they answer for (the KPI key is UTC hour, ceiling and data directory; a panel's key is its board slug and its definition). Nothing is cached inside an open transaction, because those rows may roll back.
    • New HOME_TTL_MS = 60_000.
    • A test-only clock, setHomeClock.
    • cachedKpis and cachedVitals take an optional compute argument for tests.
  • cachedWaiting is unchanged: it still misses on any write and lasts 30 s at most, so the asks count stays exact.
  • test/home-cache-ttl.test.ts (new): cachedKpis runs compute once across 50 writes, still once at 59 s, and again at 61 s on the injected clock. Panels (each kept under its own key) and vitals behave the same. Nothing is kept inside a transaction, and the waiting line still misses after a write. The gate takes every test/*.test.ts by default, so this file runs without being listed.
  • docs/CACHING.md: one passage on the 60 s rule.

Two existing tests changed because their old expectation is what this issue reverses:

  • test/home-cache.test.ts: the first test expected a write to cause a miss. It now expects a hit after the write.
  • test/observability-budget.test.ts ("a cold home answers within a few passes over the runs"): it used a write to make home cold. It now also clears the KPI, panel and vitals caches to get the cold view; the time budget it checks is the same.

Not done: readKpis itself, migrations, and the stale-refresh path (the next issue). A figure on the owner's home can now be up to 60 s old.

Checks: bun x tsc --noEmit is clean. scripts/fast.ts named 908 test files, too many to run here, so I ran the home, KPI, vitals, pins, studio, caching-doc and observability-budget tests: all pass.

To try it, open / as the owner twice within a minute while the forge is busy. The second response's server-timing shows kpis and panels with desc="hit".

🤖 Generated with Claude Code

commented

Home now keeps its KPI figures, pinned-panel answers and vitals for 60 seconds from when they were computed, no matter what is written in the meantime (#7624). Before this, the cache was cleared on every write, and the forge writes every second, so it never hit. The waiting line still clears on writes, so the count of asks stays exact.

This update merges main. In src/web/studio/home_cache.ts, main (#7689) added a time?: KpiTimer argument to cachedKpis so Server-Timing can name each part of readKpis. That argument stays fourth, as main has it, so kpi_row.ts needs no change. The test-only compute argument now comes after it and passes time through to readKpis. The cache still lasts 60 seconds and skips caching inside a transaction. test/home-cache-ttl.test.ts now passes undefined for time before its counting function; that is a signature change, not a fix to the tests.

bun x tsc --noEmit passes, and the home cache, TTL, observability budget, KPI and Server-Timing tests pass (95 across 10 files).

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("every slot busy: no reason is shown") and the decider saw no point in another try try 1: docs/CACHING.md, src/web/studio/home_cache.ts, test/home-cache-ttl.test.ts, test/home-cache.test.ts (+1 more) try 2: AGENTS.md, README.md, docs/APPS.md, docs/CLI.md (+219 more)

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs