Fix D1 dashboard recent items query#910
Conversation
🦋 Changeset detectedLatest commit: 9a2af65 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 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/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@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-forms
@emdash-cms/plugin-webhook-notifier
commit: |
|
Closing as a duplicate of #896. I missed that #896 already fixes #895 with the same per-collection recent-items approach, has a changeset, and has green CI. The only notable difference in this PR was a D1-like regression test that rejects compound |
There was a problem hiding this comment.
Pull request overview
This PR fixes the dashboard’s “recent items” query so it no longer triggers D1’s low compound-SELECT limit. In the core API, it replaces the cross-collection UNION ALL approach with per-collection capped queries that are merged in application code, while keeping the dashboard response shape unchanged.
Changes:
- Reworked
fetchRecentItems()to query each collection separately, merge the results in JS, and return the top 10 most recently updated items. - Added a regression-oriented unit test intended to guard against reintroducing a compound recent-items query on D1.
- Added a patch changeset for the published
emdashpackage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/core/src/api/handlers/dashboard.ts |
Replaces the dashboard recent-items SQL strategy with per-collection queries plus JS merge/sort/limit logic. |
packages/core/tests/unit/api/dashboard-handlers.test.ts |
Adds a new regression test for the D1 compound-select failure mode. |
.changeset/stale-actors-sneeze.md |
Records the patch release note for the D1 dashboard fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const rejectCompoundSelectPlugin = { | ||
| transformQuery(args) { | ||
| if (JSON.stringify(args.node).includes(" UNION ALL ")) { |
| const d1LikeDb = db.withPlugin(rejectCompoundSelectPlugin); | ||
| const result = await handleDashboardStats(d1LikeDb); |
What does this PR do?
Fixes the D1 dashboard 500 from recent-items loading by replacing the single cross-collection
UNION ALLquery with per-collection capped queries that are merged and limited in JS. This preserves the dashboard API shape while avoiding D1's low compound SELECT limit on sites with many collections.Closes #895
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
Not visual.
Local targeted checks:
GitHub CI is passing, including Typecheck, Lint, Tests, Integration Tests, Browser Tests, Smoke Tests, E2E shards, Format, Version Check, Validate Plugins, and Validate PR.
Additional review: