perf: getSiteSetting() piggybacks on cached getSiteSettings()#664
Conversation
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.
🦋 Changeset detectedLatest commit: fc1e988 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | fc1e988 | Apr 19 2026, 02:58 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: |
There was a problem hiding this comment.
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.astroinline 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.
…-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
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
Checklist
AI-generated code disclosure