From e9e1fdd2468ee2a3b1c9d297ebe7b917f91eb089 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Fri, 3 Apr 2026 07:40:05 +0200 Subject: [PATCH] feat: implement PostgreSQL client for bulk data retrieval to replace per-article HTTP requests --- src/lib/pg-ff-client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/pg-ff-client.ts b/src/lib/pg-ff-client.ts index 86f2b54..d4f20dc 100644 --- a/src/lib/pg-ff-client.ts +++ b/src/lib/pg-ff-client.ts @@ -753,6 +753,10 @@ export interface StockBySite { export async function pgGetStockForCodeins(codeins: string[]): Promise> { if (codeins.length === 0) return new Map(); + // Drizzle expands JS arrays into individual $1,$2,... params regardless of syntax, + // hitting PostgreSQL's 1664-entry ROW expression limit. Use sql.raw() with an escaped + // literal array instead — codeins come from the DB so single-quote escaping is sufficient. + const arrayLiteral = codeins.map(c => `'${String(c).replace(/'/g, "''")}'`).join(","); const result = await pgNoParallel(sql` SELECT a.codein, @@ -760,7 +764,7 @@ export async function pgGetStockForCodeins(codeins: string[]): Promise();