Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Debounce/throttle external API calls triggered by frequent events
Coalesce per-event external submissions into at most one call per interval to avoid rate-limiting.
Bad example
| 1 | async function onArticleChanged(update: Update): Promise<void> { |
| 2 | await applyUpdate(update); |
| 3 | await submitToSearchConsole(); // fires on every single event |
| 4 | } |
Explanation (EN)
Calling the third-party API on every event means dozens or hundreds of submissions per hour, which providers treat as spam and stop processing.
Objašnjenje (HR)
Pozivanje API-ja treće strane na svaki događaj znači desetke ili stotine slanja na sat, što pružatelji tretiraju kao spam i prestaju obrađivati.
Good example
| 1 | const submit = throttle(() => submitToSearchConsole(), 5 * 60 * 1000); |
| 2 |
|
| 3 | async function onArticleChanged(update: Update): Promise<void> { |
| 4 | await applyUpdate(update); |
| 5 | submit(); // at most one submission per 5 minutes |
| 6 | } |
Explanation (EN)
Throttling collapses bursts of events into a single submission per interval, staying within the provider's tolerance.
Objašnjenje (HR)
Throttling sažima nalete događaja u jedno slanje po intervalu, ostajući unutar tolerancije pružatelja.
Notes (EN)
Alternatively submit only on full rebuilds rather than on incremental deltas.
Bilješke (HR)
Alternativno, šalji samo pri punim ponovnim izgradnjama, a ne na inkrementalne delte.