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 ruleP2stack specificStack: node
databaseormperformancepagination
Use a combined find-and-count call instead of separate count and find queries
When you need both a page of rows and the total count with the same filter, use the ORM's findAndCountAll-style call rather than issuing two separate queries.
PR: hegnar-investor-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const total = await this.repo.count({ where }); |
| 2 | const rows = await this.repo.findAll({ where, limit, offset }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const { count: total, rows } = await this.repo.findAndCountAll({ where, limit, offset }); |
Explanation (EN)
Objašnjenje (HR)