From a3617e71ebcd77374e97cbbe790a7290b58ca236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 20 Jun 2024 09:59:23 +0200 Subject: [PATCH] perf: Reduce polling interval for read only users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/services/PollingBackend.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/services/PollingBackend.js b/src/services/PollingBackend.js index 96a9260de18..739da92feed 100644 --- a/src/services/PollingBackend.js +++ b/src/services/PollingBackend.js @@ -27,6 +27,12 @@ const FETCH_INTERVAL_MAX = 5000 */ const FETCH_INTERVAL_SINGLE_EDITOR = 5000 +/** + * Interval to check for changes for read only users + * @type {number} + */ +const FETCH_INTERVAL_READ_ONLY = 30000 + /** * Interval to fetch for changes when a browser window is considered invisible by the * page visibility API https://developer.mozilla.org/de/docs/Web/API/Page_Visibility_API @@ -120,7 +126,9 @@ class PollingBackend { } const disconnect = Date.now() - COLLABORATOR_DISCONNECT_TIME const alive = sessions.filter((s) => s.lastContact * 1000 > disconnect) - if (alive.length < 2) { + if (this.#syncService.connection.state.document.readOnly) { + this.maximumReadOnlyTimer() + } else if (alive.length < 2) { this.maximumRefetchTimer() } else { this.increaseRefetchTimer() @@ -193,6 +201,10 @@ class PollingBackend { this.#fetchInterval = FETCH_INTERVAL_SINGLE_EDITOR } + maximumReadOnlyTimer() { + this.#fetchInterval = FETCH_INTERVAL_READ_ONLY + } + visibilitychange() { if (document.visibilityState === 'hidden') { this.#fetchInterval = FETCH_INTERVAL_INVISIBLE