summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2016-04-14 11:12:15 +0200
committerChristoph Wurst <christoph@owncloud.com>2016-04-18 14:19:26 +0200
commit2d772eaaa8dfe6a8aeba9a67b50fafd2c74c0c0c (patch)
tree9391eeef11d62c9420716076bdc94c20500f1765 /core/js
parent54f6c05c79a1d01c32c016477c6ae2220e754b13 (diff)
downloadnextcloud-server-2d772eaaa8dfe6a8aeba9a67b50fafd2c74c0c0c.tar.gz
nextcloud-server-2d772eaaa8dfe6a8aeba9a67b50fafd2c74c0c0c.zip
Debounce heartbeat ajax calls to lower the number of requests
fixes #22397
Diffstat (limited to 'core/js')
-rw-r--r--core/js/js.js12
-rw-r--r--core/js/tests/specs/coreSpec.js4
2 files changed, 12 insertions, 4 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 598e0dcd185..802b5de7e18 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1498,9 +1498,15 @@ function initCore() {
interval = maxInterval;
}
var url = OC.generateUrl('/heartbeat');
- setInterval(function(){
- $.post(url);
- }, interval * 1000);
+ var heartBeatTimeout = null;
+ var heartBeat = function() {
+ clearTimeout(heartBeatTimeout);
+ heartBeatTimeout = setInterval(function() {
+ $.post(url);
+ }, interval * 1000);
+ };
+ $(document).ajaxComplete(heartBeat);
+ heartBeat();
}
// session heartbeat (defaults to enabled)
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index f18ecbc1a44..09271f1ab9a 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -305,6 +305,7 @@ describe('Core base tests', function() {
counter++;
xhr.respond(200, {'Content-Type': 'application/json'}, '{}');
});
+ $(document).off('ajaxComplete'); // ignore previously registered heartbeats
});
afterEach(function() {
clock.restore();
@@ -312,6 +313,7 @@ describe('Core base tests', function() {
window.oc_config = oldConfig;
routeStub.restore();
$(document).off('ajaxError');
+ $(document).off('ajaxComplete');
});
it('sends heartbeat half the session lifetime when heartbeat enabled', function() {
/* jshint camelcase: false */
@@ -340,7 +342,7 @@ describe('Core base tests', function() {
clock.tick(20 * 1000);
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 */
window.oc_config = {
session_keepalive: false,