Some cooldown concurrency fixes. It still needs some more testing.

This commit is contained in:
Nicolas Stepien 2012-10-03 01:01:28 +02:00
parent c2491a7f66
commit 6bafe5189c
2 changed files with 26 additions and 11 deletions

View File

@ -1829,7 +1829,7 @@
disabled = true; disabled = true;
QR.cooldown.auto = false; QR.cooldown.auto = false;
} }
value = QR.cooldown.seconds || data.progress || value; value = data.progress || QR.cooldown.seconds || value;
input = QR.status.input; input = QR.status.input;
input.value = QR.cooldown.auto && Conf['Cooldown'] ? value ? "Auto " + value : 'Auto' : value || 'Submit'; input.value = QR.cooldown.auto && Conf['Cooldown'] ? value ? "Auto " + value : 'Auto' : value || 'Submit';
return input.disabled = disabled || false; return input.disabled = disabled || false;
@ -1868,7 +1868,10 @@
return QR.cooldown.count(); return QR.cooldown.count();
}, },
sync: function(cooldowns) { sync: function(cooldowns) {
QR.cooldown.cooldowns = cooldowns; var id;
for (id in cooldowns) {
QR.cooldown.cooldowns[id] = cooldowns[id];
}
return QR.cooldown.start(); return QR.cooldown.start();
}, },
set: function(data) { set: function(data) {
@ -1902,12 +1905,14 @@
return $.set("" + g.BOARD + ".cooldown", QR.cooldown.cooldowns); return $.set("" + g.BOARD + ".cooldown", QR.cooldown.cooldowns);
}, },
count: function() { count: function() {
var cooldown, cooldowns, elapsed, hasFile, isReply, isSage, now, post, seconds, start, type, types, _ref; var cooldown, cooldowns, elapsed, hasFile, isReply, isSage, now, post, seconds, start, type, types, update, _ref;
if (Object.keys(QR.cooldown.cooldowns).length) { if (Object.keys(QR.cooldown.cooldowns).length) {
setTimeout(QR.cooldown.count, 1000); setTimeout(QR.cooldown.count, 1000);
} else { } else {
$["delete"]("" + g.BOARD + ".cooldown"); $["delete"]("" + g.BOARD + ".cooldown");
QR.cooldown.isCounting = false; delete QR.cooldown.isCounting;
delete QR.cooldown.seconds;
QR.status();
return; return;
} }
if ((isReply = g.REPLY ? true : QR.threadSelector.value !== 'new')) { if ((isReply = g.REPLY ? true : QR.threadSelector.value !== 'new')) {
@ -1929,7 +1934,7 @@
} }
continue; continue;
} }
type = isReply && cooldown.isReply ? isSage && cooldown.isSage ? 'sage' : hasFile && cooldown.hasFile ? 'file' : 'post' : !(isReply || cooldown.isReply) ? type = 'thread' : void 0; type = isReply && cooldown.isReply ? isSage && cooldown.isSage ? 'sage' : hasFile && cooldown.hasFile ? 'file' : 'post' : !(isReply || cooldown.isReply) ? 'thread' : void 0;
if (type) { if (type) {
elapsed = Math.floor((now - start) / 1000); elapsed = Math.floor((now - start) / 1000);
if (elapsed >= 0) { if (elapsed >= 0) {
@ -1941,8 +1946,9 @@
QR.cooldown.unset(start); QR.cooldown.unset(start);
} }
} }
update = seconds !== null || !!QR.cooldown.seconds;
QR.cooldown.seconds = seconds; QR.cooldown.seconds = seconds;
if (seconds !== null) { if (update) {
QR.status(); QR.status();
} }
if (seconds === 0 && QR.cooldown.auto) { if (seconds === 0 && QR.cooldown.auto) {

View File

@ -1406,7 +1406,7 @@ QR =
value = 404 value = 404
disabled = true disabled = true
QR.cooldown.auto = false QR.cooldown.auto = false
value = QR.cooldown.seconds or data.progress or value value = data.progress or QR.cooldown.seconds or value
{input} = QR.status {input} = QR.status
input.value = input.value =
if QR.cooldown.auto and Conf['Cooldown'] if QR.cooldown.auto and Conf['Cooldown']
@ -1434,7 +1434,10 @@ QR =
QR.cooldown.isCounting = true QR.cooldown.isCounting = true
QR.cooldown.count() QR.cooldown.count()
sync: (cooldowns) -> sync: (cooldowns) ->
QR.cooldown.cooldowns = cooldowns # Add each cooldowns, don't overwrite everything in case we
# still need to purge one in the current tab to auto-post.
for id of cooldowns
QR.cooldown.cooldowns[id] = cooldowns[id]
QR.cooldown.start() QR.cooldown.start()
set: (data) -> set: (data) ->
return unless Conf['Cooldown'] return unless Conf['Cooldown']
@ -1471,7 +1474,9 @@ QR =
setTimeout QR.cooldown.count, 1000 setTimeout QR.cooldown.count, 1000
else else
$.delete "#{g.BOARD}.cooldown" $.delete "#{g.BOARD}.cooldown"
QR.cooldown.isCounting = false delete QR.cooldown.isCounting
delete QR.cooldown.seconds
QR.status()
return return
if (isReply = if g.REPLY then true else QR.threadSelector.value isnt 'new') if (isReply = if g.REPLY then true else QR.threadSelector.value isnt 'new')
@ -1502,7 +1507,7 @@ QR =
else else
'post' 'post'
else unless isReply or cooldown.isReply else unless isReply or cooldown.isReply
type = 'thread' 'thread'
if type if type
elapsed = Math.floor (now - start) / 1000 elapsed = Math.floor (now - start) / 1000
if elapsed >= 0 # clock changed since then? if elapsed >= 0 # clock changed since then?
@ -1511,8 +1516,12 @@ QR =
unless start <= now <= cooldown.timeout unless start <= now <= cooldown.timeout
QR.cooldown.unset start QR.cooldown.unset start
# Update the status when we change posting type.
# Don't get stuck at some random number.
# Don't interfere with progress status updates.
update = seconds isnt null or !!QR.cooldown.seconds
QR.cooldown.seconds = seconds QR.cooldown.seconds = seconds
QR.status() if seconds isnt null QR.status() if update
QR.submit() if seconds is 0 and QR.cooldown.auto QR.submit() if seconds is 0 and QR.cooldown.auto
quote: (e) -> quote: (e) ->