gitoria
All repositories: gitoria
1.5 KB
// 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)// 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.// 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.// 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.// limitCheck(appId, method) → 0 when the request may go on, else the seconds the app has to wait (the Retry-After value)import { now } from 'hl:time'import { envOr, idiv } from './util.hl'static counts = {} // "<appId> r" / "<appId> w" → { start (ms), n }static numberEnv = (name, fallback) => {n = toNumber(envOr(name, '' + fallback))return n != null && n >= 1 ? n : fallback}static readLimit = numberEnv('GITORIA_LIMIT_READS', 300)static writeLimit = numberEnv('GITORIA_LIMIT_WRITES', 60)static windowMs = numberEnv('GITORIA_LIMIT_WINDOW_MS', 60000)static limitCheck = (appId, method) => {isRead = method == 'GET'key = appId + (isRead ? ' r' : ' w')cap = isRead ? readLimit : writeLimitt = now()row = counts[key]if (row == null || t - row.start >= windowMs) {counts[key] = { start = t n = 1 }return 0}if (row.n >= cap) {left = idiv(row.start + windowMs - t + 999, 1000)return left < 1 ? 1 : left}row.n = row.n + 1counts[key] = rowreturn 0}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- b00860e3Create repositories with member checks in createRepoInmre
- 0a38f236Report repository creation API blockermre
- b5f72187Record malformed JSON blocker for repository creationmre
- a2ae8302logmre
- 6947cd58logmre
- 2175e48clogmre
- 40eb3ca1gitoria#38: review package, logmre
- 06a5a50egitoria#38: deploy b8252ca, logmre
- b8252ca0gitoria#46: W46b report, logmre
- 50093aafgitoria#46: statuses keyed by app + context (merge w46b-keyed)mre
- dd0267edgitoria#46: fix a label in the keyed gatemre
- b1dcb580gitoria#46: statuses keyed by app + context, required = app + context, old rows still readmre
- 2287363egitoria#47: W47 report, logmre
- 9f502db1gitoria#46: W46b briefmre
- 9678a8f3gitoria#46: contract v1.4, statuses keyed by app + contextmre
- bdcbbaa9gitoria#47: rate limits, status read route, statuses + required on the pull (merge w47-limits)mre
- 772c401fgitoria#45: W45 report, logmre
- b6b793afgitoria#45: PR page with reviews, threads, conversation, Review again (merge w45-pr-page)mre
- fb9e7554gitoria#45: browser gate: a /pulls title links to the PR pagemre
- f7198131gitoria#45: tests/pr-page.mjs gatemre