mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-22 06:28:09 +02:00
feat: implement PostgreSQL client for bulk data retrieval to replace per-article HTTP requests
This commit is contained in:
1 parent
5a506c750c
commit
e9e1fdd246
1 file changed
+5
-1
@@ -753,6 +753,10 @@ export interface StockBySite {
|
|||||||
export async function pgGetStockForCodeins(codeins: string[]): Promise<Map<string, StockBySite>> {
|
export async function pgGetStockForCodeins(codeins: string[]): Promise<Map<string, StockBySite>> {
|
||||||
if (codeins.length === 0) return new Map();
|
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`
|
const result = await pgNoParallel(sql`
|
||||||
SELECT
|
SELECT
|
||||||
a.codein,
|
a.codein,
|
||||||
@@ -760,7 +764,7 @@ export async function pgGetStockForCodeins(codeins: string[]): Promise<Map<strin
|
|||||||
cs.stockdispo::float AS stockdispo
|
cs.stockdispo::float AS stockdispo
|
||||||
FROM cube_stock cs
|
FROM cube_stock cs
|
||||||
JOIN articles a ON a.no_id = cs.artnoid
|
JOIN articles a ON a.no_id = cs.artnoid
|
||||||
WHERE a.codein = ANY(${codeins}::text[])
|
WHERE a.codein = ANY(ARRAY[${sql.raw(arrayLiteral)}])
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const map = new Map<string, StockBySite>();
|
const map = new Map<string, StockBySite>();
|
||||||
|
|||||||
Reference in new issue
Block a user