Merge pull request #23990 from owncloud/heartbeat-debounce
Debounce heartbeat ajax calls to lower the number of requests
This commit is contained in:
commit
6b66f2dfb4
|
@ -1499,9 +1499,15 @@ function initCore() {
|
||||||
interval = maxInterval;
|
interval = maxInterval;
|
||||||
}
|
}
|
||||||
var url = OC.generateUrl('/heartbeat');
|
var url = OC.generateUrl('/heartbeat');
|
||||||
setInterval(function(){
|
var heartBeatTimeout = null;
|
||||||
$.post(url);
|
var heartBeat = function() {
|
||||||
}, interval * 1000);
|
clearTimeout(heartBeatTimeout);
|
||||||
|
heartBeatTimeout = setInterval(function() {
|
||||||
|
$.post(url);
|
||||||
|
}, interval * 1000);
|
||||||
|
};
|
||||||
|
$(document).ajaxComplete(heartBeat);
|
||||||
|
heartBeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
// session heartbeat (defaults to enabled)
|
// session heartbeat (defaults to enabled)
|
||||||
|
|
|
@ -305,6 +305,7 @@ describe('Core base tests', function() {
|
||||||
counter++;
|
counter++;
|
||||||
xhr.respond(200, {'Content-Type': 'application/json'}, '{}');
|
xhr.respond(200, {'Content-Type': 'application/json'}, '{}');
|
||||||
});
|
});
|
||||||
|
$(document).off('ajaxComplete'); // ignore previously registered heartbeats
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
clock.restore();
|
clock.restore();
|
||||||
|
@ -312,6 +313,7 @@ describe('Core base tests', function() {
|
||||||
window.oc_config = oldConfig;
|
window.oc_config = oldConfig;
|
||||||
routeStub.restore();
|
routeStub.restore();
|
||||||
$(document).off('ajaxError');
|
$(document).off('ajaxError');
|
||||||
|
$(document).off('ajaxComplete');
|
||||||
});
|
});
|
||||||
it('sends heartbeat half the session lifetime when heartbeat enabled', function() {
|
it('sends heartbeat half the session lifetime when heartbeat enabled', function() {
|
||||||
/* jshint camelcase: false */
|
/* jshint camelcase: false */
|
||||||
|
@ -340,7 +342,7 @@ describe('Core base tests', function() {
|
||||||
clock.tick(20 * 1000);
|
clock.tick(20 * 1000);
|
||||||
expect(counter).toEqual(2);
|
expect(counter).toEqual(2);
|
||||||
});
|
});
|
||||||
it('does no send heartbeat when heartbeat disabled', function() {
|
it('does not send heartbeat when heartbeat disabled', function() {
|
||||||
/* jshint camelcase: false */
|
/* jshint camelcase: false */
|
||||||
window.oc_config = {
|
window.oc_config = {
|
||||||
session_keepalive: false,
|
session_keepalive: false,
|
||||||
|
|
Loading…
Reference in New Issue