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:
co-authored by
Claude Opus 5.5
parent
d45175739f
commit
54c9d3ec10
@@ -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`). */
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user