Skip to content

perf: getSiteSetting() piggybacks on cached getSiteSettings()#664

Merged
ascorbic merged 2 commits into
mainfrom
peek-site-setting
Apr 19, 2026
Merged

perf: getSiteSetting() piggybacks on cached getSiteSettings()#664
ascorbic merged 2 commits into
mainfrom
peek-site-setting

Conversation

@ascorbic
Copy link
Copy Markdown
Collaborator

What does this PR do?

Follow-up to #663.

Adds `peekRequestCache(key)` to `request-cache.ts` — looks up an entry without inserting one. Returns the cached promise if present, undefined otherwise.

`getSiteSetting(key)` now peeks for the "siteSettings" cache entry first. If a parent template has already called `getSiteSettings()` (which is request-cached), the singular call reads the key out of that batch instead of firing its own options-table round-trip. Falls back to the per-key cached query when nothing has been primed.

Why

After #663, `getSiteSetting(key)` was cached per-key — so two calls to `getSiteSetting("seo")` share a query. But `EmDashHead`'s call still cost one primary-routed options read on every page render, because the narrower singular cache didn't know about the broader plural cache. On the blog-demo fixture, the Base layout already calls `getSiteSettings()` up-front; this PR makes `EmDashHead`'s SEO lookup free (reads from that already-resolved batch).

Measured

Query-count snapshot unchanged in CI (the call already fires in the measured routes' Base layout ordering). Real wins on sites where a layout pulls the full settings object and then EmDashHead / plugins ask for individual keys — that's most real sites.

Type of change

  • Performance improvement

Checklist

  • I have read CONTRIBUTING.md
  • `pnpm typecheck` passes
  • `pnpm lint` passes
  • `pnpm test` passes (2418 core tests)
  • `pnpm format` has been run
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

Adds peekRequestCache() to request-cache.ts so a narrower query can
opportunistically satisfy itself from a broader one already loaded.

getSiteSetting(key) now first peeks for the "siteSettings" batch
result (populated by getSiteSettings()) and reads the requested key
from there if present. Falls back to a per-key cached query if the
batch hasn't been loaded.

Net effect on the blog-demo layout: getSiteSettings() is already
called by Base.astro, so the EmDashHead getSiteSetting("seo") call
from PR #613 now costs zero extra queries instead of one
primary-routed round-trip per render. Query-count snapshot is
unchanged — the +1 queries PR #663 couldn't dedupe are now gone.
Copilot AI review requested due to automatic review settings April 19, 2026 14:56
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 19, 2026

🦋 Changeset detected

Latest commit: fc1e988

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

This PR includes changesets to release 12 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/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

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 19, 2026

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 fc1e988 Apr 19 2026, 02:58 PM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 19, 2026

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

emdash

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

create-emdash

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

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

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: fc1e988

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves request-level performance by letting getSiteSetting(key) reuse the already-request-cached getSiteSettings() batch when it has been loaded earlier in the same request, avoiding redundant options-table reads (notably for EmDashHead’s SEO lookup).

Changes:

  • Added peekRequestCache(key) to allow non-inserting lookups into the request-scoped cache.
  • Updated getSiteSetting(key) to opportunistically read from the primed "siteSettings" cached promise before falling back to per-key caching.
  • Updated EmDashHead.astro inline docs to reflect the new caching behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/core/src/settings/index.ts getSiteSetting() now piggybacks on the "siteSettings" cached batch when present, otherwise uses the existing per-key request cache.
packages/core/src/request-cache.ts Introduces peekRequestCache() for reading an existing request-cache entry without inserting one.
packages/core/src/components/EmDashHead.astro Comment update explaining why getSiteSetting("seo") is now “free” when getSiteSettings() has already run.
.changeset/peek-site-setting.md Patch changeset describing the caching behavior improvement and the new internal helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ascorbic ascorbic merged commit 002d0ac into main Apr 19, 2026
36 checks passed
@ascorbic ascorbic deleted the peek-site-setting branch April 19, 2026 15:07
@emdashbot emdashbot Bot mentioned this pull request Apr 19, 2026
0aveRyan pushed a commit to 0aveRyan/emdash that referenced this pull request Apr 27, 2026
…-cms#664)

* perf: getSiteSetting(key) piggybacks on cached getSiteSettings()

Adds peekRequestCache() to request-cache.ts so a narrower query can
opportunistically satisfy itself from a broader one already loaded.

getSiteSetting(key) now first peeks for the "siteSettings" batch
result (populated by getSiteSettings()) and reads the requested key
from there if present. Falls back to a per-key cached query if the
batch hasn't been loaded.

Net effect on the blog-demo layout: getSiteSettings() is already
called by Base.astro, so the EmDashHead getSiteSetting("seo") call
from PR emdash-cms#613 now costs zero extra queries instead of one
primary-routed round-trip per render. Query-count snapshot is
unchanged — the +1 queries PR emdash-cms#663 couldn't dedupe are now gone.

* add changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants