Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Reduce polling interval for read only users #5930

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/services/PollingBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Loading