Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(server): GitHub rate limits read the response headers #16986

Mergedjuliusmarmingemerged 3 commits intot3code/github-fold-repository-api fromrefs/pull/16986/headmerged by juliusmarminge View on GitHub

Showing 10 changed files with 12 additions and 4 deletions (loading 9).

x
0 of 10 viewed, 10 left
12 additions and 4 deletionsapps/server/scripts/measure-pr-preview.tsModified
View file
@@ -1,7 +1,7 @@
// Run with: node apps/server/scripts/measure-pr-preview.ts owner/repo 123 456
// Numbers form a session with shared repository-permission caches. Browser and
// service caches are excluded. Uses real GitHub reads, without a server or database.
-// Every GraphQL read carries `rateLimit`, so its cost is read off its own answer.
+// Each GraphQL read asks for `rateLimit` here, so its cost is read off its own answer.
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as Effect from "effect/Effect";
import * as Console from "effect/Console";
@@ -15,7 +15,7 @@
import * as GitHubApi from "../src/sourceControl/GitHubApi.ts";
import * as GitHubCredentials from "../src/sourceControl/GitHubCredentials.ts";
import * as ServerSettings from "../src/serverSettings.ts";
-import * as GitHubGraphQlBudget from "../src/sourceControl/githubGraphQlBudget.ts";
+import * as GitHubQuota from "../src/sourceControl/githubQuota.ts";
import * as SourceControlRateLimit from "../src/sourceControl/SourceControlRateLimit.ts";
import * as VcsProcess from "../src/vcs/VcsProcess.ts";
​
@@ -33,6 +33,14 @@
}),
),
);
+/** The query with GitHub's own count of what it cost, for a read rather than a mutation. */
+function withRateLimit(query: string): string {
+ const end = query.lastIndexOf("}");
+ return query.trimStart().startsWith("mutation") || end === -1
+ ? query
+ : `${query.slice(0, end)}\n rateLimit { cost }\n${query.slice(end)}`;
+}