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

[stable28] fix: Safeguard sync requests to hopefully not spam then server #5593

Merged
merged 1 commit into from Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/sessions.js
Expand Up @@ -27,6 +27,8 @@ const SESSION_INTERVAL = 90 // in seconds

let hasPush = false

let syncRunning = false

/**
* used to verify, whether an event is originated by ourselves
*
Expand Down Expand Up @@ -103,12 +105,24 @@ export function createSession(boardId) {
create()
return
}

if (syncRunning) {
return
}

try {
syncRunning = true
await sessionApi.syncSession(boardId, await tokenPromise)
} catch (err) {
// session probably expired, let's
// create a fresh session
create()
if (err.response.status === 404) {
// session probably expired, let's
// create a fresh session
create()
} else {
console.error('Failed to sync deck session', err)
}
} finally {
syncRunning = false
}
}

Expand All @@ -134,6 +148,7 @@ export function createSession(boardId) {
store.dispatch('refreshBoard', store.state.currentBoard?.id)

// restart session refresh interval
clearInterval(interval)
interval = setInterval(ensureSession, SESSION_INTERVAL * 1000)
}
}
Expand Down