Skip to content

Commit

Permalink
UI: Fix race in update issue labels and assignees (#6194)
Browse files Browse the repository at this point in the history
Fix #6191 

* fix issue update race condition
* fix similar race same race when clearing assignee
* always load promise polyfill
* replace es6-promise with promise-polyfill
* move promise-polyfill to <head>
  • Loading branch information
silverwind authored and zeripath committed Feb 28, 2019
1 parent 4a2e92b commit 8e266c3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
57 changes: 30 additions & 27 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,19 @@ function initBranchSelector() {
});
}

function updateIssuesMeta(url, action, issueIds, elementId, afterSuccess) {
$.ajax({
type: "POST",
url: url,
data: {
"_csrf": csrf,
"action": action,
"issue_ids": issueIds,
"id": elementId
},
success: afterSuccess
function updateIssuesMeta(url, action, issueIds, elementId) {
return new Promise(function(resolve) {
$.ajax({
type: "POST",
url: url,
data: {
"_csrf": csrf,
"action": action,
"issue_ids": issueIds,
"id": elementId
},
success: resolve
})
})
}

Expand Down Expand Up @@ -348,6 +350,10 @@ function uploadFile(file, callback) {
xhr.send(formData);
}

function reload() {
window.location.reload();
}

function initImagePaste(target) {
target.each(function(i, field) {
field.addEventListener('paste', function(event){
Expand Down Expand Up @@ -385,18 +391,20 @@ function initCommentForm() {
$('.' + selector).dropdown('setting', 'onHide', function(){
hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var
if (hasLabelUpdateAction) {
var promises = [];
for (var elementId in labels) {
if (labels.hasOwnProperty(elementId)) {
var label = labels[elementId];
updateIssuesMeta(
var promise = updateIssuesMeta(
label["update-url"],
label["action"],
label["issue-id"],
elementId
);
promises.push(promise);
}
}
location.reload();
Promise.all(promises).then(reload);
}
});

Expand Down Expand Up @@ -479,8 +487,7 @@ function initCommentForm() {
"clear",
$listMenu.data('issue-id'),
""
);
$listMenu.data('action', 'update'); // Update to reload the page when we updated items
).then(reload);
}

$(this).parent().find('.item').each(function () {
Expand Down Expand Up @@ -518,9 +525,8 @@ function initCommentForm() {
$menu.data('update-url'),
"",
$menu.data('issue-id'),
$(this).data('id'),
function() { location.reload(); }
);
$(this).data('id')
).then(reload);
}
switch (input_id) {
case '#milestone_id':
Expand All @@ -545,9 +551,8 @@ function initCommentForm() {
$menu.data('update-url'),
"",
$menu.data('issue-id'),
$(this).data('id'),
function() { location.reload(); }
);
$(this).data('id')
).then(reload);
}

$list.find('.selected').html('');
Expand Down Expand Up @@ -801,7 +806,7 @@ function initRepository() {
function (data) {
$editInput.val(data.title);
$issueTitle.text(data.title);
location.reload();
reload();
});
return false;
});
Expand Down Expand Up @@ -1786,7 +1791,7 @@ function u2fRegistered(resp) {
data: JSON.stringify(resp),
contentType: "application/json; charset=utf-8",
success: function(){
window.location.reload();
reload();
},
fail: function (xhr, textStatus) {
u2fError(1);
Expand Down Expand Up @@ -2073,9 +2078,7 @@ $(document).ready(function () {
return this.dataset.issueId;
}).get().join();
var url = this.dataset.url
updateIssuesMeta(url, action, issueIDs, elementId, function() {
location.reload();
});
updateIssuesMeta(url, action, issueIDs, elementId).then(reload);
});

buttonsClickOnEnter();
Expand Down Expand Up @@ -2912,7 +2915,7 @@ function updateDeadline(deadlineString) {
contentType: 'application/json',
type: 'POST',
success: function () {
window.location.reload();
reload();
},
error: function () {
$('#deadline-loader').removeClass('loading');
Expand Down
6 changes: 3 additions & 3 deletions public/vendor/librejs.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@
<td><a href="https://github.com/moment/moment/archive/2.22.2.tar.gz">0.4.1.tar.gz</a></td>
</tr>
<tr>
<td><a href="./plugins/es6-promise/">es6-promise</a></td>
<td><a href="https://github.com/stefanpenner/es6-promise/blob/master/LICENSE">MIT</a></td>
<td><a href="https://github.com/stefanpenner/es6-promise/archive/v4.2.6.tar.gz">4.2.6.tar.gz</a></td>
<td><a href="./plugins/promise-polyfill/">promise-polyfill</a></td>
<td><a href="https://github.com/taylorhakes/promise-polyfill/blob/master/LICENSE">MIT</a></td>
<td><a href="https://github.com/taylorhakes/promise-polyfill/archive/8.1.0.tar.gz">8.1.0.tar.gz</a></td>
</tr>
</tbody>
</table>
Expand Down
1 change: 0 additions & 1 deletion public/vendor/plugins/es6-promise/es6-promise.auto.min.js

This file was deleted.

1 change: 1 addition & 0 deletions public/vendor/plugins/promise-polyfill/polyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion templates/base/footer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
<script src="{{AppSubUrl}}/vendor/plugins/semantic/semantic.min.js"></script>
<script src="{{AppSubUrl}}/js/index.js?v={{MD5 AppVer}}"></script>
{{if .EnableHeatmap}}
<script src="{{AppSubUrl}}/vendor/plugins/es6-promise/es6-promise.auto.min.js" charset="utf-8"></script>
<script src="{{AppSubUrl}}/vendor/plugins/moment/moment.min.js" charset="utf-8"></script>
<script src="{{AppSubUrl}}/vendor/plugins/vue-calendar-heatmap/vue-calendar-heatmap.browser.js" charset="utf-8"></script>
<script type="text/javascript">
Expand Down
1 change: 1 addition & 0 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
{{end}}
<style class="list-search-style"></style>

<script src="{{AppSubUrl}}/vendor/plugins/promise-polyfill/polyfill.min.js"></script>
<script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/loadCSS.min.js"></script>
<script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/cssrelpreload.min.js"></script>
{{if .PageIsUserProfile}}
Expand Down

0 comments on commit 8e266c3

Please sign in to comment.