gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitaafe330daafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmreaafe330d/lib/limits.hl

1.5 KB

  1. // lib/limits.hl — THE RATE LIMIT OF AN APP (gitoria#47; contract docs/apps-api.md §6): per app id, per minute, 300 reads (GET) and 60 writes (POST / PUT)
  2. // over every apps API route. A fixed window: the first request of an app opens a window of one minute, the count restarts when it is over.
  3. // The counts live IN THIS PROCESS (a static map, not a table): a restart or a deploy swap starts every app at zero again, two processes count apart.
  4. // GITORIA_LIMIT_READS / GITORIA_LIMIT_WRITES / GITORIA_LIMIT_WINDOW_MS are GATE-ONLY knobs (like GITORIA_EVENTS_RETRY_MS); the defaults are the contract's.
  5. // limitCheck(appId, method) → 0 when the request may go on, else the seconds the app has to wait (the Retry-After value)
  6. import { now } from 'hl:time'
  7. import { envOr, idiv } from './util.hl'
  8. static counts = {} // "<appId> r" / "<appId> w" → { start (ms), n }
  9. static numberEnv = (name, fallback) => {
  10. n = toNumber(envOr(name, '' + fallback))
  11. return n != null && n >= 1 ? n : fallback
  12. }
  13. static readLimit = numberEnv('GITORIA_LIMIT_READS', 300)
  14. static writeLimit = numberEnv('GITORIA_LIMIT_WRITES', 60)
  15. static windowMs = numberEnv('GITORIA_LIMIT_WINDOW_MS', 60000)
  16. static limitCheck = (appId, method) => {
  17. isRead = method == 'GET'
  18. key = appId + (isRead ? ' r' : ' w')
  19. cap = isRead ? readLimit : writeLimit
  20. t = now()
  21. row = counts[key]
  22. if (row == null || t - row.start >= windowMs) {
  23. counts[key] = { start = t n = 1 }
  24. return 0
  25. }
  26. if (row.n >= cap) {
  27. left = idiv(row.start + windowMs - t + 999, 1000)
  28. return left < 1 ? 1 : left
  29. }
  30. row.n = row.n + 1
  31. counts[key] = row
  32. return 0
  33. }

Branches

Latest commits

  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre
  • 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre
  • 153c344bRestore organization metadata exposed by the whole-image comparisonmre
  • 917a1465Update status gate assertions for the referenced state rulemre
  • 3cdb02c6Own settings feedback styles and explain connection-state classesmre
  • 00d5d6c4Reference code-entry styles and nest code-browser media and pseudosmre
  • 3c425eddReference PR content styles and explain dynamic state classesmre
  • e46fa222Own shell feedback styles and retain documented selector formsmre
  • c26084c4Reference repository list styles and nest its breakpointmre
  • f3e196b5Document Markdown direct-child selector remaindersmre
  • 70597528Reference pull list rules and explain runtime class predicatesmre
  • 1ce7ac24Reference ticket row and feedback styles from its Viewmre
  • 10cdf54bGive organization repository rows their own Style referencesmre
  • 0d019521Document shared class selectors in the styles-only filemre
  • c67404a7Scope token labels and feedback through the token Viewmre
  • 944e3dabScope key names, fingerprints and errors to the keys Viewmre
  • 7bcf7bc2Nest repo navigation media rules and document selector gapsmre
  • 46a76272Reference release row styles from the Viewmre