Repository navigation
perf(core): drop redundant author_id lookup after list fetch - #838
Conversation
The byline hydration helper used to refetch `author_id` from the content table for every entry without explicit byline credits, even though the loader already exposes `data.authorId` on each row. Pass it through from the call site so the inferred-byline fallback uses the value already in hand. Saves ~30 queries across the perf-fixture suite, including 4 on post-detail.
🦋 Changeset detectedLatest commit: d80ad1c 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 |
Query-count snapshot changes32 routes changed, total Δ -60 queries. SQLite
D1
Comparing snapshot files between base and head. Updated automatically on each push. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-perf-coordinator | d80ad1c | Apr 29 2026, 08:39 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-i18n | d80ad1c | Apr 29 2026, 08:39 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | d80ad1c | Apr 29 2026, 08:39 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | d80ad1c | Apr 29 2026, 08:40 PM |
@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: |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | d80ad1c | Apr 29 2026, 08:40 PM |
|
/review |
|
LGTM! |
There was a problem hiding this comment.
Pull request overview
Improves runtime byline hydration performance by eliminating a redundant database lookup for author_id during batch byline resolution.
Changes:
- Refactors
getBylinesForEntriesto accept{ id, authorId }entry references instead of entry ID strings, avoiding a follow-upSELECT id, author_id .... - Updates the internal caller (
hydrateEntryBylinesinquery.ts) and unit tests to pass throughdata.authorId. - Updates query-count snapshots and adds a changeset documenting the perf win.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| scripts/query-counts.snapshot.sqlite.json | Updates SQLite perf snapshot query counts to reflect fewer round-trips. |
| scripts/query-counts.snapshot.d1.json | Updates D1 perf snapshot query counts to reflect fewer round-trips. |
| packages/core/tests/unit/bylines/bylines-query.test.ts | Adjusts unit tests to the new getBylinesForEntries signature. |
| packages/core/src/query.ts | Passes {id, authorId} refs into batch byline lookup during hydration. |
| packages/core/src/bylines/index.ts | Changes batch byline lookup signature and removes now-unneeded author-id batch helper. |
| .changeset/drop-redundant-author-id-lookup.md | Adds release note for the performance improvement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * import { getBylinesForEntries, getEmDashCollection } from "emdash"; | ||
| * | ||
| * const { entries } = await getEmDashCollection("posts"); | ||
| * const ids = entries.map(e => e.data.id); | ||
| * const bylinesMap = await getBylinesForEntries("posts", ids); | ||
| * const refs = entries.map((e) => ({ id: e.data.id, authorId: e.data.authorId ?? null })); | ||
| * const bylinesMap = await getBylinesForEntries("posts", refs); |
There was a problem hiding this comment.
The JSDoc example shows import { getBylinesForEntries, getEmDashCollection } from "emdash", but getBylinesForEntries is not exported from the public entrypoint (packages/core/src/index.ts only re-exports getByline/getBylineBySlug), and the package exports map blocks deep imports. This example will fail for consumers; either remove/adjust the public-facing example and mark this API as internal, or expose getBylinesForEntries via the package exports if it’s intended to be public.
Adds the query-dump harness and analysis scripts that produced the catalogue used to drive PRs #838, #839, #840: - scripts/query-counts-dump.mjs — sibling of query-counts.mjs that emits per-route × phase NDJSON dumps under scripts/query-dumps/. - scripts/build-perf-d1.mjs — standalone "build the perf fixture for d1" wrapper, useful when iterating with the dump harness without re-running the full counts harness. - scripts/query-dumps/{classify,cold-only,inspect-other}.mjs — analysis helpers for slicing the dumps. classify.mjs writes a markdown classification report; cold-only.mjs surfaces the d1 cold-isolate tax; inspect-other.mjs prints distinct SQL for a class. - scripts/query-dumps/README.md — workflow doc. The dump JSON itself and the generated classification.{target}.md reports stay gitignored — they're analysis artefacts that regenerate from the harness in seconds. The query-dumps analysis scripts are excluded from oxlint (one-off tooling, not production code).
What does this PR do?
getBylinesForEntrieswas issuingSELECT id, author_id FROM ec_<table> WHERE id IN (...)after every collection list / single-entry fetch — but the loader already exposesdata.authorIdon every entry it returns (packages/core/src/loader.ts:103, populated viaINCLUDE_IN_DATA). The lookup was re-fetching a column the caller already had in scope.The fix changes the internal
getBylinesForEntries(collection, entryIds: string[])signature to(collection, entries: { id, authorId | null }[])and updates the single in-tree caller (hydrateEntryBylinesinquery.ts) to passdata.authorIdthrough. The unusedgetAuthorIdshelper is removed; the singulargetAuthorIdstays forgetEntryBylines's rare-path fallback.getBylinesForEntriesis internal — not re-exported frompackages/core/src/index.ts. Verified there are no external imports acrosspackages/,demos/,templates/, orfixtures/.Snapshot diff (sqlite, fixtures/perf-site)
~30 fewer round-trips per harness run; post-detail down 4 (it has 3 list fetches plus the entry fetch). The d1 snapshot will be refreshed by the
query-counts-applyworkflow.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