diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-04-20 21:23:10 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2016-04-20 21:23:10 +0200 |
commit | 6b66f2dfb40bc8e3e8670fe80a9fe68dd7e418ed (patch) | |
tree | 5bb9c11878d611c62454ffef999dac641e127946 | |
parent | 42b25f78216e55f5ba08eecb2f629128883cf801 (diff) | |
parent | 2d772eaaa8dfe6a8aeba9a67b50fafd2c74c0c0c (diff) | |
download | nextcloud-server-6b66f2dfb40bc8e3e8670fe80a9fe68dd7e418ed.tar.gz nextcloud-server-6b66f2dfb40bc8e3e8670fe80a9fe68dd7e418ed.zip |
Merge pull request #23990 from owncloud/heartbeat-debounce
Debounce heartbeat ajax calls to lower the number of requests
-rw-r--r-- | core/js/js.js | 12 | ||||
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/core/js/js.js b/core/js/js.js index ac1d582a9f8..1d3ec6ec778 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1499,9 +1499,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 83441104289..02eb1b95c1d 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, |