Skip to content

Commit

Permalink
fix(Polling): Perform computations in milliseconds
Browse files Browse the repository at this point in the history
The collaborator disconnect timeout is in ms as are all intervals.
So we can directly subtract it from `Date.now()` - which also is in ms.
The only time that is not expressed in ms is the last contact timestamp.

Backport of #3769

Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Feb 8, 2023
1 parent a9ceb40 commit d8ef625
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/services/PollingBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class PollingBackend {
return
}
this.lock = false
if (response.data.sessions.filter((session) => session.lastContact > Date.now() / 1000 - COLLABORATOR_DISCONNECT_TIME).length < 2) {
const disconnect = Date.now() - COLLABORATOR_DISCONNECT_TIME
const alive = response.data.sessions.filter((s) => s.lastContact * 1000 > disconnect)
if (alive.length < 2) {
this.maximumRefetchTimer()
} else {
this.increaseRefetchTimer()
Expand Down

0 comments on commit d8ef625

Please sign in to comment.