Skip to content

Commit

Permalink
Added 2s delay b/w queries to avoid exceeding GitHub secondary rate …
Browse files Browse the repository at this point in the history
…limit.
  • Loading branch information
evoluteur committed Jun 1, 2022
1 parent afba08f commit 135a696
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) => ({
Expand Down Expand Up @@ -330,6 +340,7 @@ const getFans = (repo) => {
};

const cbFans = (data, hasError) => {
sleep();
let curStars = "skip";
let curForks = "skip";
if (!hasError) {
Expand Down

0 comments on commit 135a696

Please sign in to comment.