Make catalog refresh atomic#2847
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2847 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 73 73
Lines 12215 12207 -8
=====================================
+ Misses 12215 12207 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
simonw
marked this pull request as ready for review
July 14, 2026 15:40
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.
Refs:
Summary
catalog_databasesand replace the five child catalog tables in oneexecute_write_fn()transactionprepare_connectionplugin enables foreign-key enforcementWhy
The previous refresh committed the
catalog_databasesupdate, catalog deletion, and five insertion batches separately. Readers could observe an updated schema version with empty or partially rebuilt catalog tables, and each refresh paid for seven transactions.The new flow prepares the replacement rows first and then applies the complete per-database catalog update atomically. A failure restores the previous catalog through the outer transaction.
This implements the atomic catalog refresh recommendation from the Datasette transaction report.
Performance
A local microbenchmark used Python 3.14.3, a persistent internal database, repeated schema changes, and generated schemas; setup and schema mutation were excluded from timing.
For 300 tables, median improved 15.3% and p95 improved 41.9%. Measured transactions per refresh fell from seven to one.
Validation
uv run pytest -q— 2,294 passed, 40 skipped, 6 xfailed, 15 xpassed, 141 subtests passeduv run pytest -q tests/test_internal_db.py— 11 passeduv run black --check datasette/app.py datasette/utils/internal_db.py tests/test_internal_db.pyuv run ruff check datasette/app.py datasette/utils/internal_db.py tests/test_internal_db.pygit diff --check