Skip to content

Commit 90dc02a

Browse files
committed
Introduce a progress bar for the rate limiter (closes #14)
1 parent 35d6125 commit 90dc02a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

website/src/queries-init.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const UF_TABLE_SEPARATOR = "|";
1111
const UF_MSG_ERROR = "There seems to have been an error.<br>"
1212
+ "Maybe you had a typo in the provided input? Or the Access Token credentials are invalid?<br>"
1313
+ "If the scan is continuing, ignore this: the GitHub API some times returns erroneous data.";
14-
const UF_MSG_SLOWER = "The scan is slowing down (and will stall for a little while) due to the high amount of requests.<br>"
14+
const UF_MSG_SLOWER = "The scan will stall for a little while due to the high amount of requests.<br>"
1515
+ "(This is to prevent GitHub API from refusing to respond due to thinking those requests are malicious.)";
1616
const UF_MSG_API_RATE = "<b>GitHub API rate-limits exceeded.</b> Consider providing an <b>Access Token</b> if you haven't already (click the button at the top-right).<br>"
1717
+ "The amount of API calls you are allowed to do will re-accumulate over time: you can try again later on.<br>"
@@ -107,6 +107,7 @@ function clearMsg() {
107107
.empty()
108108
.removeClass("box")
109109
.css("border-style", "");
110+
removeProgressBar();
110111
}
111112
function clearNonErrorMsg() {
112113
const msg = JQ_ID_MSG.html();
@@ -120,6 +121,13 @@ function clearHeader() {
120121
JQ_ID_HEADER.empty();
121122
}
122123

124+
function getJq_ProgressBar() {
125+
return $(".progress");
126+
}
127+
function removeProgressBar() {
128+
getJq_ProgressBar().remove();
129+
}
130+
123131
/* Search Query Fields */
124132
function enableQueryFields() {
125133
JQ_REPO_FIELD.prop('disabled', false);

website/src/queries-logic.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ function request_fork_page(page_number, user, repo, defaultBranch) {
217217
page: page_number
218218
});
219219
const onSuccess = (responseHeaders, responseData) => {
220+
removeProgressBar();
221+
220222
if (isEmpty(responseData)) // repo has not been forked
221223
return;
222224

@@ -338,9 +340,25 @@ function setUpOctokitWithLatestToken() {
338340
return true; // true = retry
339341
}
340342
},
341-
onSecondaryRateLimit: (retryAfter, options, octokit) => {
343+
onSecondaryRateLimit: (retryAfter, options, octokit) => { // slow down
342344
setMsg(UF_MSG_SLOWER);
343-
return true; // true = automatically retry after given amount of seconds (usually 60)
345+
346+
// setup the progress bar
347+
if (!getJq_ProgressBar()[0]) { // only if it isn't displayed yet
348+
JQ_ID_MSG.after(`<progress class="progress is-small" value="${retryAfter}" max="${retryAfter}">some%</progress>`);
349+
getJq_ProgressBar().animate(
350+
{value: "0"}, // target for the "value" attribute
351+
{
352+
duration: 1000 * retryAfter, // in ms
353+
easing: 'linear',
354+
done: function() {
355+
getJq_ProgressBar().removeAttr('value'); // for moving bar
356+
}
357+
}
358+
);
359+
}
360+
361+
return true; // true = automatically retry after given amount of seconds (usually 1 min)
344362
}
345363
}
346364
});

0 commit comments

Comments
 (0)