SPB Git

spb/airiskindex Public

The most methodologically rigorous, fully transparent AI job-exposure index.

TypeScript 88% Python 6.1% SQL 2.7% CSS 1.2% JavaScript 0.9% Shell 0.8%

fix(worker): recompute loads per-occupation with minimal selects (avoid 1GB payload overflow)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
simon-pierre boucher committed 6 days ago (Aug 5, 2026) parent c4e07c4

Showing 1 changed file with +25 and −12

modified apps/worker/src/scripts/recompute.ts +25 −12
@@ -31,16 +31,10 @@ function bandFromPanel(values: number[]): RatingBand {
31 31 }
32 32
33 33 async function main(): Promise<void> {
34 const occupations = await prisma.occupation.findMany({
35 include: {
36 tasks: {
37 include: {
38 ratings: { where: { promptVersion: RATER_PROMPT_VERSION } },
39 overrides: true,
40 },
41 },
42 },
43 });
34 + // Load occupations lazily, one at a time, selecting only the rating fields
35 + // the computation needs — a full include would materialize every raw API
36 + // response (~1 GB of JSON) in one query and overflow the engine bridge.
37 + const occupationCodes = await prisma.occupation.findMany({ select: { code: true } });
44 38
45 39 const run = await prisma.scoreRun.create({
46 40 data: {
@@ -53,7 +47,26 @@ async function main(): Promise<void> {
53 47 let scoredOccupations = 0;
54 48 let skippedTasks = 0;
55 49
56 for (const occupation of occupations) {
50 + for (const { code } of occupationCodes) {
51 + const occupation = await prisma.occupation.findUniqueOrThrow({
52 + where: { code },
53 + select: {
54 + code: true,
55 + tasks: {
56 + select: {
57 + id: true,
58 + importance: true,
59 + ratings: {
60 + where: { promptVersion: RATER_PROMPT_VERSION },
61 + select: { dimension: true, rating: true },
62 + },
63 + overrides: {
64 + select: { dimension: true, ratingLow: true, ratingMid: true, ratingHigh: true },
65 + },
66 + },
67 + },
68 + },
69 + });
57 70 const inputs: TaskInput[] = [];
58 71
59 72 for (const task of occupation.tasks) {
@@ -133,7 +146,7 @@ async function main(): Promise<void> {
133 146 }
134 147
135 148 console.log(
136 `Run ${run.id} (index ${INDEX_VERSION}, prompt ${RATER_PROMPT_VERSION}): scored ${scoredOccupations}/${occupations.length} occupations; skipped ${skippedTasks} unrated tasks.`,
149 + `Run ${run.id} (index ${INDEX_VERSION}, prompt ${RATER_PROMPT_VERSION}): scored ${scoredOccupations}/${occupationCodes.length} occupations; skipped ${skippedTasks} unrated tasks.`,
137 150 );
138 151 }
139 152
140 153