Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: node
asyncperformancepromisesdatabase
Avoid awaiting inside a loop; batch with Promise.all or a single set-based query
Sequentially awaiting one async call per iteration serializes work unnecessarily; run them concurrently with Promise.all, or replace N queries with one set-based query (e.g. WHERE id IN (...)).
PR: hegnar-investor-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | for (const id of ids) { |
| 2 | await this.repo.update(id, payload); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | await Promise.all(ids.map((id) => this.repo.update(id, payload))); |
| 2 | // or a single: UPDATE ... WHERE id IN (:ids) |
Explanation (EN)
Objašnjenje (HR)