Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Bound page data reads while preserving full-result totals
Apply cursor bounds in the backing-store data read instead of loading the full collection for every page. Compute the full filtered unique total independently so page bounds do not change its meaning.
Bad example
| 1 | type Row = { id: string; time: number }; |
| 2 | async function page(loadAll: () => Promise<Row[]>, cursor: number) { |
| 3 | const rows = await loadAll(); |
| 4 | return { total: rows.length, rows: rows.filter(row => row.time <= cursor) }; |
| 5 | } |
Explanation (EN)
Every page transfers the full collection to the application.
Objašnjenje (HR)
Svaka stranica prenosi cijelu kolekciju u aplikaciju.
Good example
| 1 | type Row = { id: string; time: number }; |
| 2 | async function page(countUnique: () => Promise<number>, readThrough: (cursor: number) => Promise<Row[]>, cursor: number) { |
| 3 | const [total, rows] = await Promise.all([countUnique(), readThrough(cursor)]); |
| 4 | return { total, rows }; |
| 5 | } |
Explanation (EN)
Bound the data read but count the complete matching set; use an atomic snapshot where consistency requires it.
Objašnjenje (HR)
Ograniči čitanje članaka, ali broji cijeli skup; koristi atomski snimak kada je potrebna dosljednost.
Notes (EN)
Deduplicate overlapping buckets before counting and preserve all source filters. Server-side aggregation may still scan the full set; do not claim constant backend cost.
Bilješke (HR)
Provjeri potpune podatke i stanje izvora prije odluke o cacheu ili završetku stranice.
Exceptions / Tradeoffs (EN)
Small explicitly bounded collections may be read whole when that is demonstrably simpler and cheaper than an extra count or aggregation.
Iznimke / Tradeoffi (HR)
Dodatna provjera nije potrebna ako postojeći ugovor već jamči traženo svojstvo.