Skip to content

perf(registry): cache discovery index responses - #1569

Open
ricardo-devis-agullo wants to merge 1 commit into
masterfrom
perf/registry-discovery-response-cache
Open

perf(registry): cache discovery index responses#1569
ricardo-devis-agullo wants to merge 1 commit into
masterfrom
perf/registry-discovery-response-cache

Conversation

@ricardo-devis-agullo

Copy link
Copy Markdown
Collaborator

Problem: GET / (packages/oc/src/registry/routes/index.ts) called repository.getComponent() for EVERY component on EVERY request, then re-rendered the whole index view (incl. 1300-line CSS) per HTML hit.

Fix:

  • Per-registry-instance response cache (new helper packages/oc/src/registry/routes/discovery-cache.ts) keyed by componentsList.lastEdit (read via getComponentsDetails, advances on publish/poll) + query variant (state/meta/theme/baseUrl/discovery flags, HTML vs JSON).
  • Repeat hit costs one cheap lastEdit read; all getComponent calls and the view re-render are skipped. HTML-with-query bypasses the cache (unbounded cardinality).
  • JSON discovery responses now send Cache-Control: public, max-age=.
  • Local/dev registries (getComponentsDetails -> null) and old mocks keep exact prior behaviour.

Invalidation: lastEdit generation change drops the previous generation (also the memory bound); plus a 50-variant cap per generation.

Verify:

  • New test/unit/registry-routes-index-cache.js (11 specs): hit skips component fetches, lastEdit change refetches, variants don't collide, Cache-Control present on JSON (miss+hit) and absent on HTML, dev fallback uncached-but-correct.
  • Full packages/oc suite (npm run test-silent): 1108 passing, 0 failing, twice.
  • Note: one earlier full run showed 10 failures in registry-with-fallback acceptance (wrong-server symptoms on shared fixed ports 3030/3031); fallback spec passes 8/8 in isolation and both subsequent full runs are green, so this is a pre-existing port-reuse flake unrelated to this diff (per-instance cache, no shared state, no lifecycle changes).

GET / fanned out to repository.getComponent() for every component on
every request and re-rendered the whole index view (incl. 1300-line
CSS) per HTML hit.

Cache built JSON/HTML discovery responses per registry instance,
keyed by componentsList.lastEdit (via getComponentsDetails, which
advances on publish/poll updates) plus the query variant
(state/meta/theme/baseUrl/discovery flags, HTML vs JSON). A repeat
hit costs one cheap lastEdit read and skips all getComponent calls
and the view re-render. HTML-with-query bypasses the cache;
JSON responses carry Cache-Control: public, max-age=<pollingInterval>.

Tests: registry-routes-index-cache (11 specs: hit skips component
fetches, lastEdit invalidation, variant isolation, Cache-Control,
local/dev fallback). Full packages/oc suite: 1108 passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant