Skip to content
Back to snapcart-api report
ReliabilityMedium

Unbounded Batch Query

src/api/export.ts:55

What's going on

The export endpoint reads every row matching a filter into memory in a single query, which grows without bound as sales data accumulates.

Why it matters

Unbounded queries are the quiet production killer: they degrade slowly until a threshold tips the process into OOM.

src/api/export.ts:55

Recommended Fix

Replace the inline query with a parameterized statement and validate the id before it ever reaches the database. A regression test is generated alongside the patch.

Before
1const rows = await db.query(2  "SELECT * FROM orders WHERE status = $1",3  [status],4);
After
1const rows = await streamRowsByPage(2  "SELECT * FROM orders WHERE status = $1",3  [status],4  { pageSize: 500 },5);
  1. Uploaddone
  2. Analyzedone
  3. Finddone
  4. Explainactive
  5. Fixupcoming
  6. Testupcoming
  7. Verifyupcoming