Repository navigation
Conversation
Every full publish stored a full copy of the site in site_snapshots and nothing deleted one. Readers only reach a snapshot through a page row's active version, and version history reads data_row_versions alone, so superseded snapshots were dead weight (439 MB, 7 of 293 in use, on one production site). persistSitePublish now deletes the snapshots no active version references, keeping the one it just wrote. Superseded version rows stay; on delete set null clears their site_snapshot_id. Migration 032 indexes data_row_versions.site_snapshot_id so that set-null does not scan the versions table per deleted snapshot. Closes CoreBunch#651 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ngocht
marked this pull request as ready for review
October 15, 2026 08:05
This branch has not been deployed
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.
Summary
Closes #651.
Every full publish stores a complete copy of the published
SiteDocumentinsite_snapshots, and nothing ever deleted one. Readers only reach a snapshot throughdata_rows.active_version_id, and version history (listDataRowVersions/getDataRowVersion) readsdata_row_versionsalone. That leaves superseded snapshots as dead weight. On one production site the table held 293 snapshots / 439 MB, and only 7 of them backed an active version.Changes:
persistSitePublishcallspruneUnreferencedSiteSnapshotsat the end of its transaction. The function deletes every snapshot that no page row's active version references, and always keeps the snapshot it just wrote.on delete set null(both dialects; SQLite runs withforeign_keys = ON) clears theirsite_snapshot_id.032_data_row_versions_site_snapshot_idxindexesdata_row_versions.site_snapshot_id. Without it, the set-null on each deleted snapshot scans the whole versions table (14k rows on that site).content-storage.mdandpublisher.md.Before merging, please decide one thing. The docs call the reassembled
PublishedPageSnapshot"the canonical audit record". After this PR, that record exists for the active version only; older versions keep their row (title/slug/publisher/time) but not the full site document. There is no rollback today, so nothing reads it. If you'd rather keep site-level history for a future rollback, the predicate can also keep the newest N snapshots.The first publish after upgrading deletes the whole backlog. A dry run of the predicate on that production Postgres, inside a read-only transaction, counted 287 snapshots / 415 MB. Operators reclaim the space with
VACUUM FULL site_snapshots(Postgres) orVACUUM(SQLite).Independent of #647, which prunes
published_runtime_assets. Both touchpersistSitePublish, but they merge cleanly in either order. I checked by merging both branches and runningbun test src/__tests__/server/: 1117 pass.Verification
bun run build— rantsc -p tsconfig.app.jsonandtsc -p tsconfig.node.json(clean)bun test— ranbun test src/__tests__/server src/__tests__/db: 1141 pass. NewpublishSiteSnapshotRetention.test.ts(real SQLite viacreateTestDb) covers two cases: (1) after three publishes only the last snapshot remains, all six version rows remain with superseded links nulled, and the page still resolves by slug; (2) a snapshot still serving a page that a later publish skipped is kept. Both fail with the prune call removed. ThecmsPublishfake DB handles the new delete.bun run lint— eslint on the changed files (clean)Checklist
🤖 Generated with Claude Code