isPathVisible shares one construction-mode read per list

MCP and search call it once per result; React cache doesn't dedupe in
route handlers, so a 50-result list read Site Settings 300 times.
Concurrent calls now share one in-flight read per locale (6 reads).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:40:02 +02:00
co-authored by Claude Opus 5.5
parent d45175739f
commit 54c9d3ec10
2 changed files with 24 additions and 1 deletions
+14 -1
View File
@@ -697,8 +697,21 @@ export function createContentHelpers({
/**
* Is this page path public right now? False for pages construction mode
* hides. The Markdown and MCP routes use it; pass it to createSearchRoute.
*
* Lists call it once per result (Promise.all). React `cache` doesn't dedupe
* in route handlers, so concurrent calls share ONE in-flight mode read per
* locale — a list of 200 pages costs one Site Settings read, not 200. The
* entry is dropped once it settles, so the next request reads fresh.
*/
const isPathVisible: PathVisibility = async (path, locale) => isPathVisibleIn(await getConstructionMode(locale), path)
const inflightMode = new Map<string, Promise<ConstructionMode>>()
const isPathVisible: PathVisibility = async (path, locale) => {
let mode = inflightMode.get(locale)
if (!mode) {
mode = getConstructionMode(locale).finally(() => inflightMode.delete(locale))
inflightMode.set(locale, mode)
}
return isPathVisibleIn(await mode, path)
}
// ── Layout ────────────────────────────────────────────────────────────────
/** Notifications → form texts in this locale (BuilderForm / RenderForm `texts`). */