Skip to content

perf(core): drop redundant author_id lookup after list fetch - #838

Merged
ascorbic merged 2 commits into
mainfrom
perf/drop-author-id-lookup
Apr 29, 2026
Merged

ascorbic merged 2 commits into
mainfrom
perf/drop-author-id-lookup

Conversation

@ascorbic

Copy link
Copy Markdown
Member

What does this PR do?

getBylinesForEntries was issuing SELECT id, author_id FROM ec_<table> WHERE id IN (...) after every collection list / single-entry fetch — but the loader already exposes data.authorId on every entry it returns (packages/core/src/loader.ts:103, populated via INCLUDE_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 (hydrateEntryBylines in query.ts) to pass data.authorId through. The unused getAuthorIds helper is removed; the singular getAuthorId stays for getEntryBylines's rare-path fallback.

getBylinesForEntries is internal — not re-exported from packages/core/src/index.ts. Verified there are no external imports across packages/, demos/, templates/, or fixtures/.

Snapshot diff (sqlite, fixtures/perf-site)

Route Before After Δ
GET / 14 12 -2
GET /posts 14 12 -2
GET /posts/building-for-the-long-term 33 29 -4
GET /pages/about 13 11 -2
GET /category/development 18/17 16/15 -2
GET /tag/webdev 16 15 -1
GET /rss.xml 6 5 -1
GET /search 14 13 -1

~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-apply workflow.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code

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-bot

changeset-bot Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d80ad1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

@github-actions github-actions Bot added the query-count changed PR diff modifies query-count snapshot files label Apr 29, 2026
@github-actions

github-actions Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Query-count snapshot changes

32 routes changed, total Δ -60 queries.

SQLite

Route Before After Δ
GET / (cold) 14 12 -2
GET / (warm) 14 12 -2
GET /category/development (cold) 18 16 -2
GET /category/development (warm) 17 15 -2
GET /pages/about (cold) 13 11 -2
GET /pages/about (warm) 13 11 -2
GET /posts (cold) 14 12 -2
GET /posts (warm) 14 12 -2
GET /posts/building-for-the-long-term (cold) 33 29 -4
GET /posts/building-for-the-long-term (warm) 33 29 -4
GET /rss.xml (cold) 6 5 -1
GET /rss.xml (warm) 6 5 -1
GET /search (cold) 14 13 -1
GET /search (warm) 14 13 -1
GET /tag/webdev (cold) 16 15 -1
GET /tag/webdev (warm) 16 15 -1

D1

Route Before After Δ
GET / (cold) 22 20 -2
GET / (warm) 14 12 -2
GET /category/development (cold) 26 24 -2
GET /category/development (warm) 17 15 -2
GET /pages/about (cold) 21 19 -2
GET /pages/about (warm) 13 11 -2
GET /posts (cold) 22 20 -2
GET /posts (warm) 14 12 -2
GET /posts/building-for-the-long-term (cold) 40 36 -4
GET /posts/building-for-the-long-term (warm) 32 28 -4
GET /rss.xml (cold) 14 13 -1
GET /rss.xml (warm) 6 5 -1
GET /search (cold) 22 21 -1
GET /search (warm) 14 13 -1
GET /tag/webdev (cold) 25 24 -1
GET /tag/webdev (warm) 16 15 -1

Comparing snapshot files between base and head. Updated automatically on each push.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator d80ad1c Apr 29 2026, 08:39 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n d80ad1c Apr 29 2026, 08:39 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs d80ad1c Apr 29 2026, 08:39 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground d80ad1c Apr 29 2026, 08:40 PM

@pkg-pr-new

pkg-pr-new Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@838

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@838

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@838

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@838

emdash

npm i https://pkg.pr.new/emdash@838

create-emdash

npm i https://pkg.pr.new/create-emdash@838

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@838

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@838

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@838

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@838

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@838

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@838

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@838

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@838

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@838

commit: d80ad1c

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache d80ad1c Apr 29 2026, 08:40 PM

@ascorbic
ascorbic requested a review from Copilot April 29, 2026 21:40
@ascorbic

Copy link
Copy Markdown
Member Author

/review

@ask-bonk

ask-bonk Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves runtime byline hydration performance by eliminating a redundant database lookup for author_id during batch byline resolution.

Changes:

  • Refactors getBylinesForEntries to accept { id, authorId } entry references instead of entry ID strings, avoiding a follow-up SELECT id, author_id ....
  • Updates the internal caller (hydrateEntryBylines in query.ts) and unit tests to pass through data.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.

Comment on lines 134 to +138
* 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);

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@ascorbic
ascorbic merged commit c22fb3a into main Apr 29, 2026
44 checks passed
@ascorbic
ascorbic deleted the perf/drop-author-id-lookup branch April 29, 2026 21:47
@emdashbot emdashbot Bot mentioned this pull request Apr 29, 2026
ascorbic added a commit that referenced this pull request Apr 30, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core cla: signed query-count changed PR diff modifies query-count snapshot files size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants