fix(registry): stop egressing scan reports on hot read paths#121
Merged
Conversation
The MCP registry listing (`/servers`, `/servers/search`), the
`/v1/bundles` list/detail, and the package server-lookup endpoints
eager-loaded entire `security_scans` rows — including the full `report`
JSON — when the only fields consumed are the four MTF certification
scalars (`certificationLevel`, `controlsPassed/Failed/Total`).
`report` averages ~16 KB TOAST-compressed on disk but ~120 KB
uncompressed over the wire (max ~700 KB). With the scan row fetched
~190k+ times since early December, this single column accounted for an
estimated ~22 GB of Supabase database egress against a 26 MB database —
the rest of the schema combined is ~1–2 GB.
Changes:
- Add `SCAN_CERT_SELECT` and project the `securityScans` relation to the
four cert fields in `findPackageForServerLookup`,
`findPackagesForServerListing`, and `findVersionWithLatestScan`. The
full report is still served by the dedicated scan endpoints, which run
their own queries.
- Narrow `getVersions` to `{ version, publishedAt, downloadCount }` — the
bundle detail page fetched every version's `manifest`/`readme`/
`serverJson`/`provenance` to emit three small fields per version.
- Add `Cache-Control: public, max-age=60, s-maxage=300` to the crawled
JSON listing/detail endpoints so a shared cache absorbs repeat hits.
Read paths only; no schema or write changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Supabase reported ~14 GB of database egress for a 26 MB database. Empirically traced (read-only, against production) to a single column.
The MCP registry listing (
/servers,/servers/search),/v1/bundleslist + detail, and the package server-lookup endpoints eager-load entiresecurity_scansrows — including the fullreportJSON — when the only fields consumed are the four MTF certification scalars (certificationLevel,controlsPassed/Failed/Total).Measurements (production)
reporton disk (TOAST-compressed)reportover the wire (decompressed JSON)security_scansrows fetched since 2025-12-08reportalonepg_column_sizereports the compressed on-disk size; Postgres ships the column decompressed (7.5× expansion), which is why the egress number dwarfs the dataset. Everything else in the schema combined is ~1–2 GB.Changes
SCAN_CERT_SELECTand project thesecurityScansrelation to the four cert fields infindPackageForServerLookup,findPackagesForServerListing, andfindVersionWithLatestScan. The full report is still served by the dedicated scan endpoints (separate queries, untouched).getVersionsto{ version, publishedAt, downloadCount }— the bundle detail page was fetching every version'smanifest/readme/serverJson/provenanceto emit three small fields per version.Cache-Control: public, max-age=60, s-maxage=300to the crawled JSON listing/detail endpoints so a shared cache absorbs repeat hits.Read paths only; no schema or write changes.
Verification
pnpm typecheck,pnpm lint, andpnpm --filter @nimblebrain/mpak-registry test(134 tests) all pass.Follow-up (not in this PR)
The version-level
readme/serverJson/sourceIndexcolumns are still eager-loaded on the server-lookup paths (the secondary ~1 GB contributor). Worth a projection pass if egress doesn't drop far enough, but it requires a wider type refactor ofPackageForServerLookup.