fix: avoid D1 param limit in getEarliestSnapshotsForKeywords (#121)

This commit is contained in:
Ben Senescu 2026-04-16 12:21:08 -04:00 committed by GitHub
parent 9a9a9a2a6c
commit bc0bf894cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,7 +92,9 @@ export async function getEarliestSnapshotsForKeywords(
), ),
); );
const CHUNK_SIZE = 900; // D1 caps bound parameters at 100 per statement. The query binds N keyword
// IDs plus 4 params from the completedRunIds subquery (referenced twice).
const CHUNK_SIZE = 90;
const allResults: Awaited<ReturnType<typeof getSnapshotsForConfig>> = []; const allResults: Awaited<ReturnType<typeof getSnapshotsForConfig>> = [];
for (let i = 0; i < keywordIds.length; i += CHUNK_SIZE) { for (let i = 0; i < keywordIds.length; i += CHUNK_SIZE) {
@ -135,12 +137,7 @@ export async function getEarliestSnapshotsForKeywords(
eq(rankSnapshots.checkedAt, grouped.targetCheckedAt), eq(rankSnapshots.checkedAt, grouped.targetCheckedAt),
), ),
) )
.where( .where(inArray(rankSnapshots.runId, completedRunIds));
and(
inArray(rankSnapshots.runId, completedRunIds),
inArray(rankSnapshots.trackingKeywordId, chunk),
),
);
allResults.push(...rows); allResults.push(...rows);
} }