Skip to content

Commit 699b488

Browse files
committed
feat: Enhance GitHub API Concurrency and Rate Limit Handling (#9096)
1 parent 9eec08f commit 699b488

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

apps/devrank/services/GitHub.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,18 @@ class GitHub extends Base {
169169
if (!response.ok) {
170170
// Retry on 5xx (Server Error) or 403 (Rate Limit/Abuse)
171171
if ((response.status >= 500 || response.status === 403) && retries > 0) {
172-
const delay = (4 - retries) * 2000; // 2s, 4s, 6s
172+
let delay = (4 - retries) * 2000; // Default: 2s, 4s, 6s
173+
174+
// Special handling for 403 Secondary Rate Limit (Abuse Detection)
175+
// If we have quota remaining but get a 403, it's an abuse trigger.
176+
if (response.status === 403) {
177+
const bucket = this.rateLimit.graphql;
178+
if (bucket.remaining > 0) {
179+
console.warn(`${prefix} ⚠️ Abuse Detection triggered (403 with quota). Backing off for 10s...`);
180+
delay = 10000; // 10s penalty box
181+
}
182+
}
183+
173184
console.log(`${prefix} Error ${response.status}. Retrying in ${delay}ms...`);
174185
await new Promise(r => setTimeout(r, delay));
175186
return this.query(query, variables, retries - 1, logContext);

apps/devrank/services/Updater.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Updater extends Base {
5959
let successCount = 0;
6060
const saveInterval = config.updater.saveInterval;
6161
const whitelist = await Storage.getWhitelist();
62-
const concurrency = 10; // Increased to 10 for throughput
62+
const concurrency = 8; // Slightly reduced from 10 to balance speed vs stability
6363

6464
// Helper to process a single user
6565
const processUser = async (login) => {

0 commit comments

Comments
 (0)