From 135a696827ebc919cf4c8308ee7504a0686cd7c3 Mon Sep 17 00:00:00 2001 From: Olivier Giulieri Date: Tue, 31 May 2022 23:16:55 -0700 Subject: [PATCH] Added 2s delay b/w queries to avoid exceeding GitHub secondary rate limit. --- js/queries.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/js/queries.js b/js/queries.js index 33b4bd0..8e71ae6 100644 --- a/js/queries.js +++ b/js/queries.js @@ -5,7 +5,9 @@ */ const apiPathGraphQL = "https://api.github.com/graphql"; -const pageSize = 25; // max=100 but GitHub times out +const pageSize = 15; // max=100 but GitHub times out +const timeBwQueries = 2000; // milliseconds to wait b/w queries to avoid exceeding GitHub secondary rate limit. + let token; let login; @@ -16,6 +18,14 @@ let runningQueries; let nbErrors; let startTime; +function sleep() { + const date = Date.now(); + let currentDate = null; + do { + currentDate = Date.now(); + } while (currentDate - date < timeBwQueries); +} + const toJSON = (obj) => JSON.stringify(obj, null, 2); const formatDate = (dateString) => new Date(dateString).toLocaleDateString(); const gqlOptions = (query) => ({ @@ -330,6 +340,7 @@ const getFans = (repo) => { }; const cbFans = (data, hasError) => { + sleep(); let curStars = "skip"; let curForks = "skip"; if (!hasError) {