Limit the refresh rate increase for inactive threads to 90 seconds for visible/active tabs.

Reset the thread inactivity counter when switching to a tab.
This commit is contained in:
Nicolas Stepien 2012-07-05 18:29:32 +02:00
parent a63dad61b6
commit 41ef2b976a
2 changed files with 25 additions and 7 deletions

View File

@ -2875,7 +2875,13 @@
$.on(input, 'click', this.update); $.on(input, 'click', this.update);
} }
} }
return $.add(d.body, dialog); $.add(d.body, dialog);
return $.on(d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', function() {
Updater.unsuccessfulFetchCount = 0;
if (Updater.timer.textContent < -Conf['Interval']) {
return Updater.timer.textContent = -Updater.getInterval();
}
});
}, },
cb: { cb: {
interval: function() { interval: function() {
@ -2883,7 +2889,7 @@
val = parseInt(this.value, 10); val = parseInt(this.value, 10);
this.value = val > 5 ? val : 5; this.value = val > 5 ? val : 5;
$.cb.value.call(this); $.cb.value.call(this);
return Updater.timer.textContent = "-" + (Updater.getInterval()); return Updater.timer.textContent = -Updater.getInterval();
}, },
verbose: function() { verbose: function() {
if (Conf['Verbose']) { if (Conf['Verbose']) {
@ -2937,7 +2943,7 @@
return; return;
} }
Updater.unsuccessfulFetchCount++; Updater.unsuccessfulFetchCount++;
Updater.timer.textContent = "-" + (Updater.getInterval()); Updater.timer.textContent = -Updater.getInterval();
/* /*
Status Code 304: Not modified Status Code 304: Not modified
By sending the `If-Modified-Since` header we get a proper status code, and no response. By sending the `If-Modified-Since` header we get a proper status code, and no response.
@ -2975,7 +2981,7 @@
return; return;
} }
Updater.unsuccessfulFetchCount = 0; Updater.unsuccessfulFetchCount = 0;
Updater.timer.textContent = "-" + (Updater.getInterval()); Updater.timer.textContent = -Updater.getInterval();
scroll = Conf['Scrolling'] && Updater.scrollBG() && lastPost.getBoundingClientRect().bottom - d.documentElement.clientHeight < 25; scroll = Conf['Scrolling'] && Updater.scrollBG() && lastPost.getBoundingClientRect().bottom - d.documentElement.clientHeight < 25;
$.add(Updater.thread, nodes.reverse()); $.add(Updater.thread, nodes.reverse());
if (scroll) { if (scroll) {
@ -2987,6 +2993,9 @@
var i, j; var i, j;
i = +Conf['Interval']; i = +Conf['Interval'];
j = Math.min(this.unsuccessfulFetchCount, 9); j = Math.min(this.unsuccessfulFetchCount, 9);
if (!(d.hidden || d.oHidden || d.mozHidden || d.webkitHidden)) {
j = Math.min(j, 6);
}
return Math.max(i, [5, 10, 15, 20, 30, 60, 90, 120, 300, 600][j]); return Math.max(i, [5, 10, 15, 20, 30, 60, 90, 120, 300, 600][j]);
}, },
timeout: function() { timeout: function() {

View File

@ -2306,12 +2306,18 @@ Updater =
$.add d.body, dialog $.add d.body, dialog
$.on d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', ->
# Reset the counter when we focus this tab.
Updater.unsuccessfulFetchCount = 0
if Updater.timer.textContent < -Conf['Interval']
Updater.timer.textContent = -Updater.getInterval()
cb: cb:
interval: -> interval: ->
val = parseInt @value, 10 val = parseInt @value, 10
@value = if val > 5 then val else 5 @value = if val > 5 then val else 5
$.cb.value.call @ $.cb.value.call @
Updater.timer.textContent = "-#{Updater.getInterval()}" Updater.timer.textContent = -Updater.getInterval()
verbose: -> verbose: ->
if Conf['Verbose'] if Conf['Verbose']
Updater.count.textContent = '+0' Updater.count.textContent = '+0'
@ -2355,7 +2361,7 @@ Updater =
return return
Updater.unsuccessfulFetchCount++ Updater.unsuccessfulFetchCount++
Updater.timer.textContent = "-#{Updater.getInterval()}" Updater.timer.textContent = -Updater.getInterval()
### ###
Status Code 304: Not modified Status Code 304: Not modified
@ -2389,7 +2395,7 @@ Updater =
return unless count return unless count
Updater.unsuccessfulFetchCount = 0 Updater.unsuccessfulFetchCount = 0
Updater.timer.textContent = "-#{Updater.getInterval()}" Updater.timer.textContent = -Updater.getInterval()
scroll = Conf['Scrolling'] && Updater.scrollBG() && scroll = Conf['Scrolling'] && Updater.scrollBG() &&
lastPost.getBoundingClientRect().bottom - d.documentElement.clientHeight < 25 lastPost.getBoundingClientRect().bottom - d.documentElement.clientHeight < 25
$.add Updater.thread, nodes.reverse() $.add Updater.thread, nodes.reverse()
@ -2399,6 +2405,9 @@ Updater =
getInterval: -> getInterval: ->
i = +Conf['Interval'] i = +Conf['Interval']
j = Math.min @unsuccessfulFetchCount, 9 j = Math.min @unsuccessfulFetchCount, 9
unless d.hidden or d.oHidden or d.mozHidden or d.webkitHidden
# Don't increase the refresh rate too much on visible tabs.
j = Math.min j, 6
Math.max i, [5, 10, 15, 20, 30, 60, 90, 120, 300, 600][j] Math.max i, [5, 10, 15, 20, 30, 60, 90, 120, 300, 600][j]
timeout: -> timeout: ->