Skip to content

Commit

Permalink
Make the upload progress bar resilient to slow uploads (#6306)
Browse files Browse the repository at this point in the history
Addresses #6085
  • Loading branch information
loic-sharma authored Aug 16, 2018
1 parent 8ac0bcb commit fb22bd5
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/NuGetGallery/Scripts/gallery/async-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
var _uploadFormId;
var _uploadFormData;
var _pollingInterval = 250; // in ms
var _slowerPollingInterval = 1000; // in ms
var _pingUrl;
var _failureCount;
var _isUploadInProgress;
var _uploadStartTime;

this.init = function (pingUrl, formId, jQueryUrl, actionUrl, cancelUrl, submitVerifyUrl) {
_pingUrl = pingUrl;
Expand Down Expand Up @@ -78,7 +79,7 @@
if (InProgressPackage != null) {
bindData(InProgressPackage);
}
}
};

function resetFileSelectFeedback() {
$('#file-select-feedback').attr('value', 'Browse or Drop files to select a package...');
Expand Down Expand Up @@ -291,7 +292,7 @@

function startProgressBar() {
_isUploadInProgress = true;
_failureCount = 0;
_uploadStartTime = new Date();

setProgressIndicator(0, '');
$("#upload-progress-bar-container").removeClass("hidden");
Expand All @@ -301,6 +302,7 @@
function endProgressBar() {
$("#upload-progress-bar-container").addClass("hidden");
_isUploadInProgress = false;
_uploadStartTime = null;
}

function getProgress() {
Expand Down Expand Up @@ -334,8 +336,17 @@
}

function onGetProgressError(result) {
if (++_failureCount < 3) {
setTimeout(getProgress, _pollingInterval);
if (_uploadStartTime) {
var currentTime = new Date();
var uploadDuration = currentTime - _uploadStartTime;

// Continue polling as if no errors have occurred for the first 5 seconds of the upload.
// After that, poll at a slower pace for 5 minutes.
if (uploadDuration < 5 * 1000) {
setTimeout(getProgress, _pollingInterval);
} else if (uploadDuration < 5 * 60 * 1000) {
setTimeout(getProgress, _slowerPollingInterval);
}
}
}

Expand Down

0 comments on commit fb22bd5

Please sign in to comment.