diff --git a/src/modules/frontend/createContentHelpers.ts b/src/modules/frontend/createContentHelpers.ts index 12ac2a4..391bc65 100644 --- a/src/modules/frontend/createContentHelpers.ts +++ b/src/modules/frontend/createContentHelpers.ts @@ -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>() + 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`). */ diff --git a/test/construction.test.ts b/test/construction.test.ts index 51ac158..15412f6 100644 --- a/test/construction.test.ts +++ b/test/construction.test.ts @@ -118,6 +118,16 @@ describe('under construction — Site Settings → createPageRoute', () => { expect(await rpc('get_page', { path: '/pl/o-nas' })).toMatch(/No page found/) expect(await rpc('search_content', { locale: 'pl', query: 'nas' })).not.toContain('/pl/o-nas') + // a whole list shares one construction-mode read (React cache doesn't dedupe in route handlers) + const readsFor = async (n: number) => { + const spy = vi.spyOn(payload, 'findGlobal') + await Promise.all(Array.from({ length: n }, (_, i) => helpers.isPathVisible(`/pl/p-${i}`, 'pl'))) + const count = spy.mock.calls.length + spy.mockRestore() + return count + } + expect(await readsFor(50)).toBe(await readsFor(1)) + expect(await helpers.isPathVisible('/pl/o-nas', 'pl')).toBe(false) expect(await helpers.isPathVisible('/pl/brief', 'pl')).toBe(true) })