Repository navigation
Conversation
🦋 Changeset detectedLatest commit: b51ba37 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 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 |
There was a problem hiding this comment.
The approach fits the performance problem. Capped size counts piggyback on the existing resolveTermGroups query, so no extra round trips are added. Sorting groupSets lets the smallest filter drive the pivot seek. Both reviewers found no result-correctness regression. Postgres and single-taxonomy behavior are unchanged, and the new D1 test measures rows_read for both key orders. One finding remains: the changeset overstates how exact the smallest-filter choice is for multi-slug filters, since the estimates are conservative.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
| "emdash": patch | ||
| --- | ||
|
|
||
| Speeds up `getEmDashCollection()` listings on SQLite and D1 that filter by two or more taxonomies and no content fields. When one of the taxonomy filters has fewer than 200 assigned entries in the collection, the listing now starts from the filter with the fewest entries instead of the taxonomy the `where` object names first, so a broad taxonomy listed first no longer makes the listing read every entry assigned to it. To pick the starting filter, the term lookup reads up to about 200 extra index entries per taxonomy filter. Postgres listings are unchanged. |
There was a problem hiding this comment.
[needs fixing] The claim that any filter below 200 assignments makes the listing start from the filter with the fewest entries is not guaranteed by the implementation. For example, a first filter with two slugs having 150 and 5 assignments gets a per-group cap of 100 and is therefore estimated as 200 (loader.ts:1282,1313–1317). A second, single-slug filter with 180 assignments is then chosen over that smaller 155-assignment filter. This is a reasonable conservative heuristic, but the release note currently describes exact selection. Describe selection using bounded estimates and qualify the multi-slug case rather than promising the smallest filter whenever one falls below 200. (Only the openai reviewer raised this; the anthropic reviewer checked the cap logic and found it correct without noting the wording issue.)
@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-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
upgrade-emdash
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-ai-search
@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: |
There was a problem hiding this comment.
The approach remains appropriate for the taxonomy-query performance problem. This follow-up only revises the changeset, and it addresses the prior finding: selection is now described in terms of capped estimates, with an explicit caveat for multi-slug filters rather than a guarantee of choosing the exact smallest filter.
I checked the revised wording against the probe and sorting implementation and the changeset documentation standards. No outstanding findings or new issues in this follow-up. Review was static; no checks were run.
Follow-up review by openai/gpt-6.1-sol, scoped to the changes since the last review.
danielmlr
left a comment
There was a problem hiding this comment.
Two small things, neither blocking:
- The new D1 test only compares the two
whereorders with each other. If the sort ever picked the bigger filter, both orders would start frombroadand read about the same, so the test would still pass. Also checking that each order reads fewer rows than the 750 entries taggedbroadwould catch that. - The changeset says the lookup reads up to about 200 extra index entries per filter. With a long slug list, each slug's count reads its own entries, so the extra reads grow with the list instead of staying near 200. The docstring line "a long slug list reads about as much as a single slug" is off in the same way, so I'd fix or drop it. I'd keep the changeset to what a site owner notices, something like:
Speeds up `getEmDashCollection()` listings on SQLite and D1 that filter by two or more taxonomies and no content fields. The listing now usually starts from the smallest taxonomy filter instead of the one written first in `where`, so a broad taxonomy listed first no longer slows it down.|
Closing in favor of #3266 by @eisenbruch, which takes the same approach (capped count inside the term lookup, no extra round trip) and was opened six weeks earlier. Sorry for the overlap, I missed it when I picked up #3259. The field-filter case of #3259 is not covered by either PR and will follow separately. ~ 🤖 Claude Opus 5.5 |
What does this PR do?
On SQLite and D1, a collection listing filtered by two or more taxonomies seeks the first filter on the
content_taxonomiespivot and checks every other filter with a per-candidateEXISTS. The first filter was whichever key the caller wrote first inwhere, so{ topics, places }and{ places, topics }read very different row counts for the same result.The term lookup that already runs for each taxonomy filter now also counts that filter's pivot rows in the collection, capped at 200 index entries, inside the same query. The filters are then sorted by that count, so the smallest one drives the seek. No query is added; the per-listing query count is unchanged.
whereorder.This covers part 1 of the issue. Part 2 (a content-field filter drops the pivot path) is not in this PR.
Refs #3259
Type of change
Your connection to this 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.i18n, design PR and screenshots do not apply: no admin UI change, performance change only.
AI assistance disclosure
Screenshots / test output
Not applicable (no UI change).
Measured with D1
meta.rows_readin the newtests/workerd/loader-taxonomy-pivot-order-d1.test.ts(local D1 through@cloudflare/vitest-pool-workers). The fixture has 1,500 published entries:category: broadtags 750,category: rare5 andtag: narrow30. Each listing haslimit: 10, returns the same 10 ids in both orders and runs 3 queries in both orders, before and after.whereorderpublished_atsort{ category: "broad", tag: "narrow" }{ tag: "narrow", category: "broad" }updated_atsort (temp-sort path){ category: "broad", tag: "narrow" }{ tag: "narrow", category: "broad" }published_atsort, two slugs{ category: ["rare", "broad"], tag: "narrow" }{ tag: "narrow", category: ["rare", "broad"] }The worst order reads about half as many rows as before. The best order now pays for the size probe: up to about 200 index entries for the first filter and one past the smallest count for each later one. The gap between the orders is now bounded by that probe instead of by the size of the broadest term. When every taxonomy filter has 200 or more assignments, the filters tie and the
whereorder still decides, as it did before.The test fails on
mainin all three cases (gap of 721, 721 and 748 rows against a bound of 300). With the cap guard removed, it fails in the two-slug case (664).packages/core: 858 test files, 10,379 tests passed; workerd suite 45 files, 206 tests passed, including the existing pivot plan tests (loader-taxonomy-pivot-plan), which are unchanged.pnpm build,pnpm typecheck,pnpm formatclean;pnpm lint:jsonreports 0 diagnostics.