vetkit.data-access.query-in-loop.while
A database query runs inside a loop, once per iteration (the N+1 query pattern). The number of round trips grows with the data, so code that is fast on a development database becomes slow and holds connections for longer once real tables and lists grow.
Last updated:
Suite: Production readiness
javascript, typescript
A database query runs inside a loop, once per iteration (the N+1 query pattern). The number of round trips grows with the data, so code that is fast on a development database becomes slow and holds connections for longer once real tables and lists grow.
Category: DATABASE · Engine rule severity: WARNING
How to fix it
Load what the loop needs with one query before it (for example findMany({ where: { id: { in: ids } } }), Drizzle inArray(...), Supabase .in('id', ids), a join or an include) and look rows up in a Map inside the loop. Batch writes with the bulk API (createMany, insert(...).values([...]), insertMany, bulkCreate, an array upsert) or a single deleteMany / DELETE … WHERE id IN (…).
References
Source: packages/engine/rules/data-access/javascript.yml.
Generated from shipped rule definitions at build time. Matching is a review signal, not proof of exploitability. “generic” denotes text matching, not complete language or framework coverage. Runtime configuration and available tools affect whether a rule runs.