Await inside a loop
Why it matters
Each iteration waits for the previous round trip before starting its own: N items cost N sequential database or network latencies on the request path.
Fix
Start the calls together and await them once (await Promise.all(items.map(load))), or fetch them all in one batched query (where: { id: { in: ids } }).
Credit
From ESLint
The no-await-in-loop rule flags awaiting inside a loop because iterations then run one after another.
References
- no-await-in-loopESLint
- Promise.all() - JavaScriptMDN Web Docs
- Fetching DataNext.js