Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit cc5519b774316ade318349542bfc24fd1e4d706d
parent a8c8f0d2c127be1411c396b33f8b449df6d61d7b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu,  8 Oct 2026 23:10:29 -0400

umtool: an article's records resolve once each, in parallel

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/lib/articles/article.ts | 41+++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/umtool/lib/articles/article.ts b/umtool/lib/articles/article.ts @@ -98,9 +98,12 @@ export const corpusMediaUrl = (abs: string) => `/api/sites/media?corpus=${encode type Cite = NonNullable<Report["citations"]>[string]; -async function recordViewOf(c: Cite): Promise<RecordView | undefined> { +async function recordViewOf( + c: Cite, + metaOf: (channel: string, id: string) => Promise<RecordMeta | null> = recordMeta, +): Promise<RecordView | undefined> { if (c.kind === "video" || c.kind === "audio") { - const m = await recordMeta(c.channel, c.id); + const m = await metaOf(c.channel, c.id); return { channel: c.channel, id: c.id, @@ -132,18 +135,28 @@ async function recordViewOf(c: Cite): Promise<RecordView | undefined> { export async function articleView(report: Report): Promise<{ view: ReportPageView; error: string | null }> { const records = new Map<Cite, RecordView>(); const posts = new Map<Cite, { author?: string; text?: string; shot?: string }>(); - for (const c of Object.values(report.citations ?? {})) { - const r = await recordViewOf(c); - if (r) records.set(c, r); - if (c.kind === "post") { - const post = (await channelPosts(c.channel)).get(c.id); - const shot = await postShotFile(c.channel, c.id); - posts.set(c, { - ...(post ? { author: post.authorName ?? post.author, text: post.text } : {}), - ...(shot ? { shot: corpusMediaUrl(shot) } : {}), - }); - } - } + // A fact-check cites the same few records hundreds of times: read each once, + // all at the same time (recordMeta memoises on the file, not on a promise). + const metas = new Map<string, Promise<RecordMeta | null>>(); + const metaOf = (channel: string, id: string) => { + const k = `${channel}/${id}`; + if (!metas.has(k)) metas.set(k, recordMeta(channel, id)); + return metas.get(k)!; + }; + await Promise.all( + Object.values(report.citations ?? {}).map(async (c) => { + const r = await recordViewOf(c, metaOf); + if (r) records.set(c, r); + if (c.kind === "post") { + const post = (await channelPosts(c.channel)).get(c.id); + const shot = await postShotFile(c.channel, c.id); + posts.set(c, { + ...(post ? { author: post.authorName ?? post.author, text: post.text } : {}), + ...(shot ? { shot: corpusMediaUrl(shot) } : {}), + }); + } + }), + ); try { const view = buildReportPageView(report, { record: (c) => records.get(c as Cite) ?? { channel: c.channel, id: c.id },