mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Prevent updates from running out-of-order
This commit is contained in:
parent
d65eccbe9d
commit
f5f0bdb3bb
File diff suppressed because one or more lines are too long
@ -41,8 +41,14 @@ $(window).load(function() {
|
|||||||
upload();
|
upload();
|
||||||
}, window.debounceMS));
|
}, window.debounceMS));
|
||||||
|
|
||||||
|
var latestUpload = null, needAnother = false;
|
||||||
function upload() {
|
function upload() {
|
||||||
$.ajax({
|
// Prevent concurrent uploads
|
||||||
|
if (latestUpload != null) {
|
||||||
|
needAnother = true;
|
||||||
|
return
|
||||||
|
}
|
||||||
|
latestUpload = $.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/update',
|
url: '/update',
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
@ -51,16 +57,25 @@ $(window).load(function() {
|
|||||||
fetched_at: window.lastFetch,
|
fetched_at: window.lastFetch,
|
||||||
}),
|
}),
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
latestUpload = null;
|
||||||
|
|
||||||
$('#saveEditButton').removeClass()
|
$('#saveEditButton').removeClass()
|
||||||
if (data.success == true) {
|
if (data.success == true) {
|
||||||
$('#saveEditButton').addClass("success");
|
$('#saveEditButton').addClass("success");
|
||||||
window.lastFetch = data.unix_time;
|
window.lastFetch = data.unix_time;
|
||||||
|
|
||||||
|
if (needAnother) {
|
||||||
|
upload();
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
$('#saveEditButton').addClass("failure");
|
$('#saveEditButton').addClass("failure");
|
||||||
}
|
}
|
||||||
$('#saveEditButton').text(data.message);
|
$('#saveEditButton').text(data.message);
|
||||||
|
needAnother = false;
|
||||||
},
|
},
|
||||||
error: function(xhr, error) {
|
error: function(xhr, error) {
|
||||||
|
latestUpload = null;
|
||||||
|
needAnother = false;
|
||||||
$('#saveEditButton').removeClass()
|
$('#saveEditButton').removeClass()
|
||||||
$('#saveEditButton').addClass("failure");
|
$('#saveEditButton').addClass("failure");
|
||||||
$('#saveEditButton').text(error);
|
$('#saveEditButton').text(error);
|
||||||
|
Loading…
Reference in New Issue
Block a user