Skip to content

Commit

Permalink
fix(sync): ensure queue stays the same array
Browse files Browse the repository at this point in the history
Change the content of `queue` with `queue.splice`
rather than setting `queue` to another array.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Dec 15, 2023
1 parent 61005c5 commit 111c5d1
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/services/WebSocketPolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,20 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio
// data.forEach(logStep)

queue.push(...data)
let outbox = []
let outbox
return syncService.sendSteps(() => {
outbox = [...queue]
const data = {
steps: this.#steps,
awareness: this.#awareness,
version: this.#version,
}
queue = []
outbox = queue.splice(0, queue.length)
logger.debug('sending steps ', data)
return data
})?.catch(err => {
logger.error(err)
// try to send the steps again
queue = [...outbox, ...queue]
// Prefix the queue with the steps in outbox to send them again
queue.splice(0, 0, ...outbox)
})
}

Expand Down Expand Up @@ -126,18 +125,18 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio
if (queue.length) {
let outbox = []
return syncService.sendStepsNow(() => {
outbox = [...queue]
const data = {
steps: this.#steps,
awareness: this.#awareness,
version: this.#version,
}
queue = []
outbox = queue.splice(0, queue.length)
logger.debug('sending final steps ', data)
return data
})?.catch(err => {
logger.error(err)
queue = [...outbox, ...queue]
// Prefix the queue with the steps in outbox to send them again
queue.splice(0, 0, ...outbox)
})
}
}
Expand Down

0 comments on commit 111c5d1

Please sign in to comment.