Skip to content

Commit fb22bd5

Browse files
authored
Make the upload progress bar resilient to slow uploads (#6306)
Addresses #6085
1 parent 8ac0bcb commit fb22bd5

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/NuGetGallery/Scripts/gallery/async-file-upload.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
var _uploadFormId;
1111
var _uploadFormData;
1212
var _pollingInterval = 250; // in ms
13+
var _slowerPollingInterval = 1000; // in ms
1314
var _pingUrl;
14-
var _failureCount;
1515
var _isUploadInProgress;
16+
var _uploadStartTime;
1617

1718
this.init = function (pingUrl, formId, jQueryUrl, actionUrl, cancelUrl, submitVerifyUrl) {
1819
_pingUrl = pingUrl;
@@ -78,7 +79,7 @@
7879
if (InProgressPackage != null) {
7980
bindData(InProgressPackage);
8081
}
81-
}
82+
};
8283

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

292293
function startProgressBar() {
293294
_isUploadInProgress = true;
294-
_failureCount = 0;
295+
_uploadStartTime = new Date();
295296

296297
setProgressIndicator(0, '');
297298
$("#upload-progress-bar-container").removeClass("hidden");
@@ -301,6 +302,7 @@
301302
function endProgressBar() {
302303
$("#upload-progress-bar-container").addClass("hidden");
303304
_isUploadInProgress = false;
305+
_uploadStartTime = null;
304306
}
305307

306308
function getProgress() {
@@ -334,8 +336,17 @@
334336
}
335337

336338
function onGetProgressError(result) {
337-
if (++_failureCount < 3) {
338-
setTimeout(getProgress, _pollingInterval);
339+
if (_uploadStartTime) {
340+
var currentTime = new Date();
341+
var uploadDuration = currentTime - _uploadStartTime;
342+
343+
// Continue polling as if no errors have occurred for the first 5 seconds of the upload.
344+
// After that, poll at a slower pace for 5 minutes.
345+
if (uploadDuration < 5 * 1000) {
346+
setTimeout(getProgress, _pollingInterval);
347+
} else if (uploadDuration < 5 * 60 * 1000) {
348+
setTimeout(getProgress, _slowerPollingInterval);
349+
}
339350
}
340351
}
341352

0 commit comments

Comments
 (0)