Skip to content

fix(publish): prune stored runtime assets of superseded page versions - #647

Open
ngocht wants to merge 1 commit into
CoreBunch:mainfrom
ngocht:fix/prune-superseded-runtime-assets
Open

ngocht wants to merge 1 commit into
CoreBunch:mainfrom
ngocht:fix/prune-superseded-runtime-assets

Conversation

@ngocht

@ngocht ngocht commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Every full publish stores each page's bundled runtime files in published_runtime_assets under a fresh version path, and nothing ever deleted them. On a busy production site the table reached 206k rows / 1.5 GB of a 2 GB database. One day of editing wrote 696 MB (about 19 files / 310 KB per page version). These bytes are only a fallback behind the disk-baked copies (tryServeRuntimeAsset is disk-first), but they bloat the database and every backup.

Change: persistSitePublish now deletes, per page, the stored assets of every version other than the one being activated and the one it supersedes.

  • Nothing re-activates an old version: active_version_id is only ever set to the version being published.
  • Keeping the superseded version covers visitors still holding its HTML. That's the same window the disk's two-slot swap covers.
  • Version rows (and site_snapshots) are untouched.
  • The first publish after upgrading drops the backlog for the published pages, so that one publish does a larger delete. Operators reclaim the disk space with VACUUM FULL published_runtime_assets (Postgres) or VACUUM (SQLite).

Not in scope: site_snapshots also grow by one full site document per publish. Pruning them needs a version-history retention decision.

Verification

  • bun run build — ran tsc -p tsconfig.app.json and tsc -p tsconfig.node.json (clean)
  • bun test — ran bun test src/__tests__/server/: 1115 pass. New publishRuntimeAssetRetention.test.ts (real SQLite via createTestDb): after four publishes only the last two versions per page keep assets and all version rows remain; fails on main. The cmsPublish fake DB handles the two new queries.
  • bun run lint — eslint on the changed files (clean)
  • Docker/deployment check, if relevant

Checklist

  • Tests cover behavior changes.
  • Docs were updated when behavior, config, deployment, or public surfaces changed.
  • No compatibility shim was added for old pre-release behavior.
  • No secrets, local databases, uploads, or generated artifacts are included.

🤖 Generated with Claude Code

Every full publish stores each page's bundled runtime files in
published_runtime_assets under a fresh version path, and nothing ever
deleted them. On a busy production site the table reached 206k rows / 1.5 GB
(696 MB written in one day), bloating the database and its backups for bytes
that are only a fallback behind the disk-baked copies.

persistSitePublish now deletes, per page, the stored assets of every version
other than the one being activated and the one it supersedes. Nothing
re-activates an old version, and keeping the previous one covers visitors
still holding its HTML — the same window the disk's two-slot swap covers.
Version rows are untouched. The first publish after upgrading drops the
backlog for the published pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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