Skip to content

fix(dash): cache /api/components like /api/stats and /api/facets - #116

Merged
OsherElhadad merged 1 commit into
mainfrom
fix/dashboard-components-cache
Aug 26, 2026
Merged

OsherElhadad merged 1 commit into
mainfrom
fix/dashboard-components-cache

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

Summary

The Components page has been "loading forever." /api/components had no
cache at all — PR #108 added the 5s TTL jsonCache to /api/stats and
/api/facets, but missed this one, so the dashboard's most-read tab re-ran
all five of its queries (Components, DecomposeComponentSavedUSD,
EstimateComponentSavedUSD) cold on every single load.

Measured on a corpus matching production scale (70k requests x 7
components, 490k request_components rows, all properly indexed — this is
not a missing-index or N+1 bug):

Components():                    1.36s
DecomposeComponentSavedUSD():    2.21s
EstimateComponentSavedUSD():     0.87s
TOTAL, cold, every load:         4.44s

A tab left auto-refreshing, or two managers on the same window, each paid
that ~4.4s independently — the exact "piling up under load" pattern #108
already fixed everywhere else on this endpoint's neighbors.

(The Overview page's "sometimes a few minutes" report is the WAL-checkpoint
mechanism fixed separately in #115 — Overview shares the same *sql.DB with
the writer that /metrics does. Not re-fixed here.)

Fix

Added componentsCache alongside the existing statsCache/facetsCache
and wrapped a.components the same way a.stats already wraps Overview.
No new abstraction, no query changes.

Test plan

  • go build ./... and go vet ./... clean
  • go test ./... passes across the whole repo
  • Added TestComponentsCached — does not even compile against the
    pre-fix code (no componentsCache field) and passes against the fix

/api/components had no cache at all -- PR #108 added the 5s TTL jsonCache
to /api/stats and /api/facets but missed this one, so the dashboard's
most-read tab re-ran all five of its queries (Components,
DecomposeComponentSavedUSD, EstimateComponentSavedUSD) cold on every load.
Measured on a corpus matching production scale (70k requests x 7
components, 490k request_components rows): ~4.4s per load, every time --
a dashboard tab left auto-refreshing, or two managers on the same window,
each paid that cost independently, exactly the "piling up under load"
pattern #108 already fixed everywhere else.

Added componentsCache alongside statsCache/facetsCache and wrapped
a.components the same way a.stats already wraps Overview.

Added TestComponentsCached, which does not even compile against the
pre-fix code (no componentsCache field) and passes against the fix.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad
OsherElhadad merged commit 0fa9cf1 into main Aug 26, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant