Ratelimit progressbar update to save some cpu time
This commit is contained in:
parent
52ed170292
commit
36db8a4dc9
3 changed files with 50 additions and 3 deletions
|
@ -7,7 +7,8 @@ class Loading
|
||||||
setProgress: (percent) ->
|
setProgress: (percent) ->
|
||||||
if @timer_hide
|
if @timer_hide
|
||||||
clearInterval @timer_hide
|
clearInterval @timer_hide
|
||||||
$(".progressbar").css("width", percent*100+"%").css("opacity", "1").css("display", "block")
|
RateLimit 200, ->
|
||||||
|
$(".progressbar").css("width", percent*100+"%").css("opacity", "1").css("display", "block")
|
||||||
|
|
||||||
hideProgress: ->
|
hideProgress: ->
|
||||||
console.log "hideProgress"
|
console.log "hideProgress"
|
||||||
|
|
|
@ -10,6 +10,35 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ---- src/Ui/media/lib/RateLimit.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var call_after_interval, limits;
|
||||||
|
|
||||||
|
limits = {};
|
||||||
|
|
||||||
|
call_after_interval = {};
|
||||||
|
|
||||||
|
window.RateLimit = function(interval, fn) {
|
||||||
|
if (!limits[fn]) {
|
||||||
|
call_after_interval[fn] = false;
|
||||||
|
fn();
|
||||||
|
return limits[fn] = setTimeout((function() {
|
||||||
|
if (call_after_interval[fn]) {
|
||||||
|
fn();
|
||||||
|
}
|
||||||
|
delete limits[fn];
|
||||||
|
return delete call_after_interval[fn];
|
||||||
|
}), interval);
|
||||||
|
} else {
|
||||||
|
return call_after_interval[fn] = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/lib/ZeroWebsocket.coffee ---- */
|
/* ---- src/Ui/media/lib/ZeroWebsocket.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -555,7 +584,9 @@ jQuery.extend( jQuery.easing,
|
||||||
if (this.timer_hide) {
|
if (this.timer_hide) {
|
||||||
clearInterval(this.timer_hide);
|
clearInterval(this.timer_hide);
|
||||||
}
|
}
|
||||||
return $(".progressbar").css("width", percent * 100 + "%").css("opacity", "1").css("display", "block");
|
return RateLimit(200, function() {
|
||||||
|
return $(".progressbar").css("width", percent * 100 + "%").css("opacity", "1").css("display", "block");
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Loading.prototype.hideProgress = function() {
|
Loading.prototype.hideProgress = function() {
|
||||||
|
@ -648,6 +679,7 @@ jQuery.extend( jQuery.easing,
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/Notifications.coffee ---- */
|
/* ---- src/Ui/media/Notifications.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -1493,4 +1525,4 @@ jQuery.extend( jQuery.easing,
|
||||||
|
|
||||||
window.wrapper = new Wrapper(ws_url);
|
window.wrapper = new Wrapper(ws_url);
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
14
src/Ui/media/lib/RateLimit.coffee
Normal file
14
src/Ui/media/lib/RateLimit.coffee
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
limits = {}
|
||||||
|
call_after_interval = {}
|
||||||
|
window.RateLimit = (interval, fn) ->
|
||||||
|
if not limits[fn]
|
||||||
|
call_after_interval[fn] = false
|
||||||
|
fn() # First call is not delayed
|
||||||
|
limits[fn] = setTimeout (->
|
||||||
|
if call_after_interval[fn]
|
||||||
|
fn()
|
||||||
|
delete limits[fn]
|
||||||
|
delete call_after_interval[fn]
|
||||||
|
), interval
|
||||||
|
else # Called within iterval, delay the call
|
||||||
|
call_after_interval[fn] = true
|
Loading…
Reference in a new issue