Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Push filtering predicates into the query, not into in-memory loops
When the data store can express a filter, add it to the query instead of fetching everything and filtering in application code.
Bad example
| 1 | // Fetch all records, then filter in memory |
| 2 | const all = await searchClient.query({ index: 'instruments' }); |
| 3 | const filtered = all.filter((i) => countries.includes(i.countryCode)); |
Explanation (EN)
Fetching an unbounded result before filtering wastes work and can filter only a partial page.
Objašnjenje (HR)
Dohvat neograničenog rezultata prije filtriranja troši resurse, a paginacija može značiti da se filtrira samo dio podataka.
Good example
| 1 | // Express the filter as part of the query |
| 2 | const filtered = await searchClient.query({ |
| 3 | index: 'instruments', |
| 4 | filter: { terms: { countryCode: countries } }, |
| 5 | }); |
Explanation (EN)
The predicate is sent to the data store, which can use indexes and return only matching rows. Less data crosses the wire and there is no hand-written in-memory filtering to maintain.
Objašnjenje (HR)
Predikat se salje bazi, koja moze koristiti indekse i vratiti samo odgovarajuce retke. Manje podataka prolazi mrezom i nema rucnog filtriranja u memoriji koje treba odrzavati.
Notes (EN)
Push a selective predicate into the data query when its semantics match and doing so avoids unnecessary transfer or incorrect pagination.
Bilješke (HR)
Selektivni uvjet premjesti u podatkovni upit kada semantika ostaje ista i time se izbjegava nepotreban prijenos ili pogrešna paginacija.
Exceptions / Tradeoffs (EN)
Small bounded cached sets or derived predicates can be filtered locally. Verify collation, null handling, authorization and aggregate/pagination order before moving the filter.
Iznimke / Tradeoffi (HR)
Male ograničene cacheirane kolekcije ili izvedeni uvjeti mogu se filtrirati lokalno. Prije premještanja provjeri kolaciju, null, autorizaciju te redoslijed agregacije i paginacije.