diff --git a/apps/api/src/inventions-db.ts b/apps/api/src/inventions-db.ts index 7275034..e4d1ffc 100644 --- a/apps/api/src/inventions-db.ts +++ b/apps/api/src/inventions-db.ts @@ -1278,10 +1278,11 @@ export async function getInventionsByIds( inventionIds: number[] ): Promise { if (inventionIds.length === 0) return [] - const placeholders = inventionIds.map((_, i) => `?${i + 1}`).join(', ') + // One bound JSON array rather than a placeholder per id: D1 caps a statement at 100 + // bound variables, and the top-today window or a big collection easily passes that. const { results } = await db - .prepare(`SELECT data FROM invention WHERE id IN (${placeholders})`) - .bind(...inventionIds) + .prepare(`SELECT data FROM invention WHERE id IN (SELECT value FROM json_each(?1))`) + .bind(JSON.stringify(inventionIds)) .all() const byId = new Map()