Source code Performance Cost

N+1 DB queries — per-ID fetch inside map()

Part of the Scalability antipatterns check · fix arrives as a guide

What it is

A database query runs inside a loop or a map over a collection, issuing one round trip per item instead of one for the set.

Why it matters

The cost scales with the row count, so it is invisible with seed data and a timeout with real data. A hundred-item list becomes a hundred sequential round trips, each paying full network latency.

How to fix it

Collect the ids first and fetch them in a single query with an IN clause, or express the relationship as a join. Where the shape makes that awkward, batch the lookups through a loader that coalesces them per tick.

Run them all on your app

Connect your repo and your live services with read-only scopes. The first scan is free, and nothing changes without your approval.