diff --git a/src/pages/wiki/special/mostlinkedpages.json.ts b/src/pages/wiki/special/mostlinkedpages.json.ts index 3f7e55da..21f8dc12 100644 --- a/src/pages/wiki/special/mostlinkedpages.json.ts +++ b/src/pages/wiki/special/mostlinkedpages.json.ts @@ -43,28 +43,19 @@ export const GET: APIRoute = async ({ site }) => { const summaryBySlug = publishedSummaryBySlug(); const pageBySlug = await contentPagesBySlug(rankedSlugs); - // sectionCount is the article's table-of-contents section count — the same - // figure toc.json exposes as `count` and info.json / history.json expose on - // their envelopes, derived from the shared getArticleToc helper. Rendered only - // for the ranked pages so a consumer can gauge each top page's depth (how many - // sections it has) alongside its link popularity without a second fetch. - // Gather each ranked page's section count and revision history in a single pass - // over the ranked list. These were two separate loops over `ranked`; the history - // read is folded into the render pass so the list is traversed once. History is - // read before the no-page guard so every ranked entry still gets a history entry - // (the render/sectionCount step is what requires a resolved page), keeping the - // output byte-identical. const sectionCountBySlug: Record = {}; const historyBySlug: Record> = {}; const wordCountBySlug: Record = {}; - for (const entry of ranked) { - historyBySlug[entry.slug] = historyForSlug(entry.slug); - const page = pageBySlug[entry.slug]; - if (!page) continue; - const { headings } = await render(page); - sectionCountBySlug[entry.slug] = getArticleToc(headings).length; - wordCountBySlug[entry.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length; - } + await Promise.all( + ranked.map(async (entry) => { + historyBySlug[entry.slug] = historyForSlug(entry.slug); + const page = pageBySlug[entry.slug]; + if (!page) return; + const { headings } = await render(page); + sectionCountBySlug[entry.slug] = getArticleToc(headings).length; + wordCountBySlug[entry.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length; + }), + ); const body = JSON.stringify( { diff --git a/src/pages/wiki/special/recentchanges.json.ts b/src/pages/wiki/special/recentchanges.json.ts index 4d5cb875..28a34dee 100644 --- a/src/pages/wiki/special/recentchanges.json.ts +++ b/src/pages/wiki/special/recentchanges.json.ts @@ -53,21 +53,17 @@ export const GET: APIRoute = async ({ site }) => { // feed-member pages instead of indexing the whole collection up front. const pageBySlug = await contentPagesBySlug(feedMemberSlugs); - // sectionCount is the changed article's table-of-contents section count — the - // same figure toc.json exposes as `count` and info.json / history.json expose - // on their envelopes, derived from the shared getArticleToc helper. Rendered - // only for the changed articles in the feed so a change-feed consumer can gauge - // each article's depth without a second fetch. Cached per slug because an - // article can appear in multiple changes. const wordCountBySlug: Record = {}; const sectionCountBySlug: Record = {}; - for (const slug of feedMemberSlugs) { - const page = pageBySlug[slug]; - if (!page) continue; - const { headings } = await render(page); - sectionCountBySlug[slug] = getArticleToc(headings).length; - wordCountBySlug[slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length; - } + await Promise.all( + [...feedMemberSlugs].map(async (slug) => { + const page = pageBySlug[slug]; + if (!page) return; + const { headings } = await render(page); + sectionCountBySlug[slug] = getArticleToc(headings).length; + wordCountBySlug[slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length; + }), + ); // revisionCount/firstEdited/lastEdited are the changed article's own commit- // history stats (history is newest-first) — the same trio info.json / // allpages.json expose per article, and mostlinkedpages.json / subnets.json / diff --git a/src/pages/wiki/special/subnets.json.ts b/src/pages/wiki/special/subnets.json.ts index f3d7c926..ae66adef 100644 --- a/src/pages/wiki/special/subnets.json.ts +++ b/src/pages/wiki/special/subnets.json.ts @@ -39,34 +39,19 @@ export const GET: APIRoute = async ({ site }) => { const subnetSlugs = new Set(subnets.map((subnet) => subnet.slug)); const pageBySlug = await contentPagesBySlug(subnetSlugs); - // sectionCount is the subnet article's table-of-contents section count — the - // same figure toc.json exposes as `count` and info.json / history.json expose - // on their envelopes, derived from the shared getArticleToc helper. Rendered - // only for the registry's subnet articles so a subnet dashboard can gauge each - // subnet's depth (how many sections it documents) without a second fetch. - // Gather each subnet's section count and revision history in a single pass over - // the registry list. These were two separate loops over `subnets`; the history - // read is folded into the render pass so the list is traversed once. History is - // read before the no-page guard so every subnet still gets a history entry (the - // render/sectionCount step is what requires a resolved page), keeping output - // byte-identical. const sectionCountBySlug: Record = {}; const historyBySlug: Record> = {}; - // wordCount is only ever read by subnet.slug below, for the registry's subnet - // articles (a subset of the full page collection — e.g. 128 of ~350) — not - // every published article. Previously tokenized for the full collection up - // front; gated into this same subnets-only loop that already scopes - // sectionCount, the same compute-only-for-used-members pattern #1213 / #1232 / - // #1240 use elsewhere. const wordCountBySlug: Record = {}; - for (const subnet of subnets) { - historyBySlug[subnet.slug] = historyForSlug(subnet.slug); - const page = pageBySlug[subnet.slug]; - if (!page) continue; - const { headings } = await render(page); - sectionCountBySlug[subnet.slug] = getArticleToc(headings).length; - wordCountBySlug[subnet.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length; - } + await Promise.all( + subnets.map(async (subnet) => { + historyBySlug[subnet.slug] = historyForSlug(subnet.slug); + const page = pageBySlug[subnet.slug]; + if (!page) return; + const { headings } = await render(page); + sectionCountBySlug[subnet.slug] = getArticleToc(headings).length; + wordCountBySlug[subnet.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length; + }), + ); const body = JSON.stringify( {