fix: reduce GitHub quota use with sharing enabled (#11888)

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Bilal BakrandJulius Marminge authored and GitHub committed 2026-09-15 15:30:58 -07:00
1 parent b84f63bb13
commit f4600d77dd
20 files changed
+1020 -273

No files matched your search

@@ -85,8 +85,8 @@ export const make = Effect.gen(function* () {
function* (host, document, options) {
if (!isReadOperation(document)) return document;
const now = yield* Clock.currentTimeMillis;
const key = `${hostKey(host)}\0${yield* SourceControlRateLimit.CredentialScope}`;
const retryAt = yield* Ref.modify(snapshots, (current) => {
const key = hostKey(host);
const snapshot = current.get(key);
if (snapshot === undefined) return [null, current] as const;
if (snapshot.resetAtMs <= now) {
@@ -94,8 +94,11 @@ export const make = Effect.gen(function* () {
next.delete(key);
return [null, next] as const;
}
const remaining = Math.max(0, snapshot.remaining - Math.max(1, snapshot.cost));
if (options?.allowReserve !== true && remaining < snapshot.limit * GRAPHQL_RESERVE_RATIO) {
const remaining = snapshot.remaining - Math.max(1, snapshot.cost);
if (
remaining < 0 ||
(options?.allowReserve !== true && remaining < snapshot.limit * GRAPHQL_RESERVE_RATIO)
) {
return [snapshot.resetAtMs, current] as const;
}
const next = new Map(current);
@@ -118,8 +121,8 @@ export const make = Effect.gen(function* () {
)(function* (host, raw) {
const snapshot = snapshotFrom(raw);
if (snapshot === null) return;
const key = `${hostKey(host)}\0${yield* SourceControlRateLimit.CredentialScope}`;
yield* Ref.update(snapshots, (current) => {
const key = hostKey(host);
const previous = current.get(key);
// Concurrent reads can finish out of order. Quota only falls within one reset window, and
// an answer from an older window must not replace the current one.