Skip to content

Commit 84e340c

Browse files
committed
fix: adjust discussion processing delay to comply with GitHub's rate limit recommendations
1 parent 6ea6480 commit 84e340c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scripts/copy-discussions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
// GitHub limits content-generating requests to avoid abuse:
3030
// - No more than 80 content-generating requests per minute
3131
// - No more than 500 content-generating requests per hour
32+
// - Try to stay under 1 discussion or comment created every 3 seconds
3233
// This script includes automatic retry logic and rate limit handling to stay within these limits.
3334
// See: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits
3435

3536
// Configuration
3637
const INCLUDE_POLL_MERMAID_CHART = true; // Set to false to disable Mermaid pie chart for polls
3738
const RATE_LIMIT_SLEEP_SECONDS = 0.5; // Default sleep duration between API calls to avoid rate limiting
38-
const DISCUSSION_PROCESSING_DELAY_SECONDS = 5; // Delay between processing discussions
39+
const DISCUSSION_PROCESSING_DELAY_SECONDS = 3; // Delay between processing discussions (GitHub recommends 1 discussion per 3 seconds)
3940
const MAX_RETRIES = 3; // Maximum number of retries for failed operations (rate limits handled automatically by Octokit)
4041

4142
const { Octokit } = require("octokit");
@@ -965,8 +966,14 @@ async function copyDiscussionComments(octokit, discussionId, comments, answerCom
965966
replyCreated,
966967
reply.reactionGroups || []
967968
);
969+
970+
// Delay between replies to avoid rate limits (1 comment per 3 seconds)
971+
await sleep(DISCUSSION_PROCESSING_DELAY_SECONDS);
968972
}
969973
}
974+
975+
// Delay between comments to avoid rate limits (1 comment per 3 seconds)
976+
await sleep(DISCUSSION_PROCESSING_DELAY_SECONDS);
970977
} else {
971978
warn(`Failed to copy comment by @${author}, skipping replies`);
972979
}

0 commit comments

Comments
 (0)