Repository navigation
perf(admin): serve the content-list search filter from the FTS5 index - #1857
Conversation
🦋 Changeset detectedLatest commit: 7bfffbf 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: |
There was a problem hiding this comment.
This PR is a focused, well-justified performance fix for #1517. It routes the admin content-list q filter through the existing SQLite FTS5 index (when search is enabled and covers the display columns) while preserving the unindexable LIKE fallback for Postgres, search-disabled collections, and uncovered display columns. The approach fits EmDash's architecture: handlers decide the strategy and the repository applies it, SQL identifiers are validated before interpolation, and user input is always passed as a parameter (the MATCH expression is constructed from escaped terms and bound as a value).
I read the diff, the full changed files, the existing search/query code, the FTS manager, and the route wrappers. I traced the query paths (page + count both use the same applySearchFilter, locale filtering is applied before the search predicate) and checked AGENTS.md conventions: SQL safety, locale filtering, API envelope, changeset, and tests are all in place. The behavioral change from arbitrary substring to token-prefix + slug-prefix matching is documented and intentional.
I did not run the test suite or linters (no shell available), but the provided tests cover the new matchers, the FTS path, soft-delete sync, and the LIKE fallback. I found no blocking issues, no security issues, and no convention violations that would require changes.
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. |
The admin list filter ran lower(col) LIKE '%term%' — doubly unindexable (leading wildcard + lower() around the column) — so every keystroke scanned all non-deleted rows in the locale, twice (page fetch + count). On D1 these reads route to the primary. When the collection has search enabled and the FTS index covers the display columns, the filter now runs a token-prefix MATCH against _emdash_fts_<slug> OR'd with an index-served slug GLOB prefix. Both sides are index-backed (MULTI-INDEX OR in the query plan, no table scan). Collections without search, uncovered display columns, and Postgres keep the LIKE fallback. Fixes emdash-cms#1517
a91d419 to
7bfffbf
Compare
What does this PR do?
Fixes #1517 (milestone 1.0): the admin content-list search box generated
with a
%term%pattern — doubly unindexable (leading wildcard +lower()wrapping the column) — so every keystroke scanned all non-deleted rows in the locale, twice (page fetch + the count for the pagination denominator). On D1 these are primary reads with a terrible rows-read/rows-returned ratio.As the issue suggests, the filter now uses the FTS layer EmDash already ships. When the collection has search enabled and the index covers the display columns, the
qfilter becomes:Both sides are index-backed.
EXPLAIN QUERY PLANbefore/after on a seeded table:Design notes:
useFtsis set by the handler only when: SQLite (FTS5 is SQLite-only),search_config.enabled, every non-slug display column (title/name) is in the searchable-field set (otherwise FTS would miss matches LIKE finds), and the FTS table exists. Everything else — Postgres, search disabled, uncovered columns — keeps the existing LIKE fallback, unchanged.buildFtsPrefixMatchhelper quotes every term (interior quotes doubled) and treats FTS operators as plain words — unlike the public search API'sescapeQuery, which intentionally passes operators through. A list filter box is not a search-syntax field.slug GLOB 'term*'prefix (GLOB metacharacters escaped via character classes; GLOB's case-sensitive BINARY comparison is what lets SQLite use the ordinary slug index, and slugs are lowercase by construction).need headfinds "Needle Headline"; mid-wordeedleno longer matches). That's standard search behavior and what the FTS index can serve; the count and the page use the same filter, so the pagination denominator stays consistent.verifyAndRepairAllplus migration 039.Tests: unit tests for the two expression builders; integration tests for the FTS path (title token prefix, case-insensitivity, multi-word, slug prefix, filtered
total, literal quotes, operators as plain words, soft-delete sync) and for the LIKE fallback when a display column isn't covered by the index. The existingcontent-list-search.test.ts(both dialects) passes unchanged.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure
Screenshots / test output