Skip to content

Commit

Permalink
fixup! refactor(sync): cache steps in sync service
Browse files Browse the repository at this point in the history
  • Loading branch information
max-nextcloud committed Nov 26, 2024
1 parent 91450a2 commit c0b1bd6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,9 @@ export default {

async close() {
await this.$syncService.sendRemainingSteps()
.catch(err => logger.warn('Failed to send remaining steps', { err }))
await this.disconnect()
.catch(err => logger.warn('Failed to disconnect', { err }))
if (this.$editor) {
try {
this.unlistenEditorEvents()
Expand Down
10 changes: 3 additions & 7 deletions src/services/Outbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Outbox {

storeStep(step: Uint8Array) {
const encoded = encodeArrayBuffer(step)
if (encoded < 'AAA') {
if (encoded < 'AAA' || encoded > 'Ag') {
logger.warn('Unexpected step type:', { step, encoded })
return
}
Expand All @@ -29,11 +29,7 @@ export default class Outbox {
this.#syncUpdate = encoded
return
}
if (encoded < 'Ag') {
this.#awarenessUpdate = encoded
return
}
logger.warn('Unexpected step type:', { step, encoded })
this.#awarenessUpdate = encoded
}

getDataToSend(): Sendable {
Expand All @@ -48,7 +44,7 @@ export default class Outbox {
}

/*
* Clear data that has just been
* Clear data that has just been sent.
*
* Only clear data that has not changed in the meantime.
* @param {Sendable} - data that was to the server
Expand Down
4 changes: 2 additions & 2 deletions src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ class SyncService {
}

sendRemainingSteps() {
if (!this.outbox.hasUpdate()) {
return
if (!this.#outbox.hasUpdate) {
return Promise.resolve()
}
logger.debug('sending final steps')
return this.sendStepsNow().catch(err => logger.error(err))
Expand Down

0 comments on commit c0b1bd6

Please sign in to comment.