Archilyzer · Source

archilyzer

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

commit 84aa044aaeb1a3a19ff8723287d03272b405125c
parent 5a55e58328ee113053867f149be276fe00e1297c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 01:25:10 -0500

common: the job list walks a channel's data/ only for a row that reads the count

Every poll of the job list (/api/jobs/active, once a second per open page,
and the dashboard's and /jobs' own render) asked readChannelStat for every
listed record that named a channel: a walk of the channel's whole data/,
about a second on a channel of ten thousand videos. Only a running job
whose progress the runner did not count itself reads those counts
(computeJobProgressView); queued, finished, progress-less and
runner-counted records drew the same row without them.

needsChannelStat (jobRows.ts) states that condition once and
rowsForRecords asks only for those channels. Rows are identical: pinned
over records of every shape.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/views/activeJobs.test.ts | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Mcommon/views/activeJobs.ts | 9++++++++-
Mcommon/views/jobRows.ts | 17+++++++++++++++++
3 files changed, 100 insertions(+), 5 deletions(-)

diff --git a/common/views/activeJobs.test.ts b/common/views/activeJobs.test.ts @@ -4,6 +4,8 @@ import { defaultSiteSettings } from "../lib/settings"; import { createScheduler, type Scheduler } from "../jobs/scheduler"; import type { JobRecord } from "../jobs/registry"; import type { JobMeta } from "../jobs/jobMeta"; +import type { ChannelStat } from "../controller/channels"; +import { fromRecord, needsChannelStat } from "./jobRows"; import type { Paths } from "../lib/paths"; import type { DiskGateStatus } from "../lib/diskSpace"; import type { AutoRunnerStatus } from "../controller/autoRunner"; @@ -115,6 +117,7 @@ function harness(over: { jobs?: JobRecord[]; slots?: string[]; meta?: (id: string) => JobMeta | null; + stat?: (slug: string) => ChannelStat | null; disk?: DiskGateStatus; runner?: (kind: AutoQueueKind) => AutoRunnerStatus; } = {}): Harness { @@ -151,7 +154,7 @@ function harness(over: { now: () => NOW, channelStat: async (slug) => { statCalls.push(slug); - return null; + return over.stat?.(slug) ?? null; }, jobMeta: async (id) => { metaCalls.push(id); @@ -210,11 +213,13 @@ test("the log tail is read for stuck rows only", async () => { }); test("a channel is stat-ed once however many of its jobs are running", async () => { + // Each with progress the disk has to count: the only rows that read a stat. + const progress = { metric: "transcripts", initial: 0, target: 5 } as const; const h = harness({ jobs: [ - job({ id: "a1", channelSlug: "alpha" }), - job({ id: "a2", channelSlug: "alpha", queueKey: "q2" }), - job({ id: "b1", channelSlug: "beta", queueKey: "q3" }), + job({ id: "a1", channelSlug: "alpha", progress }), + job({ id: "a2", channelSlug: "alpha", queueKey: "q2", progress }), + job({ id: "b1", channelSlug: "beta", queueKey: "q3", progress }), // No channel at all: a corpus-wide job contributes no slug. job({ id: "c1", queueKey: "q4" }), ], @@ -374,3 +379,69 @@ test("rowsFromJobsPage folds a listing page and nothing else", () => { assert.equal(out.hasMore, true); assert.deepEqual(out.rows.map((r) => r.id), ["j9"]); }); + +// THE CHANNEL STAT IS A WALK OF THE CHANNEL'S `data/`, asked for on every poll +// of the job list. It is asked for only by a row that reads it — and every row +// comes out exactly as it did when every channel was walked. +const statOf = (slug: string): ChannelStat => ({ + slug, + config: { handling: "youtube" } as ChannelStat["config"], + playlistCount: 50, + videoCount: 40, + transcriptCount: 17, + downloadCount: 23, + digestCount: 9, +}); + +const SHAPES: JobRecord[] = [ + // Reads the stat: running, on a channel, progress the runner did not count. + job({ id: "walk-transcripts", channelSlug: "needs-t", progress: { metric: "transcripts", initial: 10, target: 30 } }), + job({ id: "walk-downloads", channelSlug: "needs-d", progress: { metric: "downloads", initial: 20, target: 30 } }), + job({ id: "walk-digests", channelSlug: "needs-g", progress: { metric: "digests", initial: 5, target: 12 } }), + // Never reads it. + job({ id: "runner-counted", channelSlug: "counted", progress: { metric: "digests", initial: 0, target: 8, current: 3 } }), + job({ id: "no-progress", channelSlug: "plain" }), + job({ id: "no-channel", progress: { metric: "clips", initial: 0, target: 4, current: 1 } }), + job({ id: "no-channel-no-progress" }), + job({ id: "queued", status: "queued", startedAt: undefined, channelSlug: "waiting", progress: { metric: "transcripts", initial: 0, target: 9 } }), + job({ id: "done", status: "done", endedAt: NOW - 5_000, channelSlug: "finished", progress: { metric: "transcripts", initial: 0, target: 9 } }), + job({ id: "failed", status: "failed", endedAt: NOW - 5_000, channelSlug: "broke" }), +]; + +test("the channel stat is read only for a row that uses it", async () => { + const h = harness({ jobs: SHAPES, stat: statOf }); + await buildActiveJobsPayload(h.inputs); + assert.deepEqual([...h.statCalls].sort(), ["needs-d", "needs-g", "needs-t"]); + assert.deepEqual( + SHAPES.filter(needsChannelStat).map((j) => j.id), + ["walk-transcripts", "walk-downloads", "walk-digests"], + ); +}); + +test("every row is the row a stat for every channel would have drawn", async () => { + const h = harness({ jobs: SHAPES, stat: statOf }); + const payload = await buildActiveJobsPayload(h.inputs); + const rows = new Map([...payload.jobs, ...payload.recent].map((r) => [r.id, r])); + assert.equal(rows.size, SHAPES.length); + for (const j of SHAPES) { + const row = rows.get(j.id); + assert.ok(row, j.id); + // The row as it was built before: the channel's stat handed to every + // record that names a channel. + const before = fromRecord(j, { + now: NOW, + stat: j.channelSlug ? statOf(j.channelSlug) : undefined, + workerNames: new Map(), + position: -1, + queueMax: 0, + }); + assert.deepEqual(row.progress, before.progress, `${j.id}: progress`); + assert.equal(row.status, before.status); + } + // And the three that read it did read it. + assert.equal(rows.get("walk-transcripts")?.progress?.current, 17); + assert.equal(rows.get("walk-downloads")?.progress?.current, 23); + assert.equal(rows.get("walk-digests")?.progress?.current, 9); + assert.equal(rows.get("runner-counted")?.progress?.current, 3); + assert.equal(rows.get("no-progress")?.progress, undefined); +}); diff --git a/common/views/activeJobs.ts b/common/views/activeJobs.ts @@ -2,6 +2,7 @@ import { fromEntry, fromRecord, fromSlot, + needsChannelStat, orderLiveRows, reconcileSlots, RECENT_MS, @@ -133,9 +134,15 @@ async function rowsForRecords( views: QueueView[], now: number, ): Promise<JobRowView[]> { + // Only the channels a row will actually read the counts of (needsChannelStat, + // jobRows.ts): the stat is a walk of the channel's `data/`, and this runs on + // every poll of the job list. const channelSlugs = Array.from( new Set( - records.map((j) => j.channelSlug).filter((s): s is string => Boolean(s)), + records + .filter(needsChannelStat) + .map((j) => j.channelSlug) + .filter((s): s is string => Boolean(s)), ), ); diff --git a/common/views/jobRows.ts b/common/views/jobRows.ts @@ -161,6 +161,23 @@ function computeEtaSeconds( return (waves * avgProcMs) / 1000; } +// WHETHER A ROW'S PROGRESS NEEDS THE CHANNEL'S ON-DISK COUNTS. The counts are +// a walk of the channel's whole `data/` (readChannelStat: a second on a +// channel of ten thousand videos), and the job list is polled every second — +// so the walk is asked for only by a row that will read it: a RUNNING job on a +// channel whose progress the runner did not count itself. Every other record +// (queued, finished, no progress snapshot, a runner-reported `current`) draws +// the same row with or without the counts; `fromRecord` and +// `computeJobProgressView` below are the two conditions this restates. +export function needsChannelStat(job: JobRecord): boolean { + return ( + job.status === "running" && + Boolean(job.channelSlug) && + job.progress !== undefined && + job.progress.current === undefined + ); +} + function computeJobProgressView( job: JobRecord, stat: ChannelStat | undefined,