gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2a89d8d02a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre2a89d8d0/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

  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre
  • 55c84779Merge branch 'gp-gate-ports' into mainGitoria
  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria
  • 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
  • 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
  • 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria
  • 698458e2|||PR No session for cookieless login errors: READMEmre
  • cce7b785|||PR No session for cookieless login errorsmre
  • 678d6303Merge branch 'v59' into mainGitoria
  • 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria