fix(taxonomies): never query a declared collection whose ec_* table is missing#2043
Open
swissky wants to merge 2 commits into
Open
fix(taxonomies): never query a declared collection whose ec_* table is missing#2043swissky wants to merge 2 commits into
swissky wants to merge 2 commits into
Conversation
… of probing missing ones The migration-seeded category/tag defs declare ["posts"] whether or not that collection exists, so on any site without a posts collection every visible-term-count computation issued a UNION that joined ec_posts and failed. The retry path made the result correct, but the failed statement itself is logged by the database — on D1 it surfaces as a "no such table: ec_posts" error span in Workers Observability, once per taxonomy per uncached render, drowning out real errors. Resolve the set of existing ec_* tables upfront (cached per isolate, reset by SchemaRegistry create/delete and by readers that observe a stale list) and scope the count to collections whose table exists, so a query referencing a missing table is never sent.
🦋 Changeset detectedLatest commit: f58d88b The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Contributor
Query-count snapshot changes4 routes changed, total Δ +4 queries. SQLite
D1
Comparing snapshot files between base and head. Updated automatically on each push. |
Contributor
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
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.
What does this PR do?
Stops term counting from issuing queries against
ec_*tables that don't exist, which currently floods D1 logs with phantomno such table: ec_postserrors on any site without apostscollection.The bug: migration
006_taxonomy_defsseeds the defaultcategory/tagdefs bound to["posts"]whether or not that collection is ever created.fetchVisibleTermCountsthen builds a UNION that joinsec_posts, catches the missing-table error, and retries per collection — the result is correct, but the failed statement itself is logged by the database. On D1 each one surfaces as ano such table: ec_posts: SQLITE_ERRORerror span in Workers Observability, once per taxonomy per uncached render, drowning out real errors. (Observed in production on a Workers + D1 site with Logs/Traces enabled; the same drift also occurs when a declared collection is deleted.)The fix: resolve the set of existing
ec_*tables upfront (via the dialect-awarelistTablesLike, same helper migration 051 uses) and scope the count to collections whose table actually exists — a failing statement is never sent. To keep the count path at one round-trip per taxonomy, the table list is cached per isolate in a newdatabase/content-tables-cache.ts(same pattern as the loader's taxonomy-names cache, including thedbIsIsolatedbypass) and reset bySchemaRegistry.createCollection/deleteCollection. A reader that still hits a dropped table (stale list from another isolate's delete) resets the cache and retries once, preserving the previous partial-but-correct behavior.The
getTermquery-budget test stays at 4 queries; it now primes the once-per-isolate table lookup so the budget reflects the steady state.Tests:
never sends a query referencing a missing ec_* table— asserts on the SQL sent through the Kysely executor; fails onmain, passes with the fix.recovers when the isolate-cached table list goes stale— covers the refresh-and-retry fallback.Possible follow-up (out of scope here): stop hardcoding
["posts"]in the migration-seeded defaults and let seeds declare the binding — happy to open a Discussion if that's of interest.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
Production log entry that motivated the fix (Workers Observability, one per taxonomy per uncached render):