Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(sync): make use of steps in push responses
The pushed steps are echoed back with all other steps since version immediately.
Processing them reduces the size of the following pushes and syncs.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud authored and backportbot[bot] committed Nov 26, 2024
commit b6e44845a04a497f2d1d6271505bb57ffc763a56
4 changes: 3 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ export default {
this.$nextTick(() => {
this.emit('sync-service:sync')
})
this.document = document
if (document) {
this.document = document
}
},

onError({ type, data }) {
Expand Down
24 changes: 12 additions & 12 deletions src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,18 @@ class SyncService {
this.sending = true
clearInterval(this.#sendIntervalId)
this.#sendIntervalId = null
const data = getSendable()
if (data.steps.length > 0) {
const sendable = getSendable()
if (sendable.steps.length > 0) {
this.emit('stateChange', { dirty: true })
}
return this.#connection.push(data)
return this.#connection.push(sendable)
.then((response) => {
const { steps } = response.data
this.pushError = 0
this.sending = false
this.emit('sync', {
steps: [],
document: this.#connection.document,
version: this.version,
})
if (steps?.length > 0) {
this._receiveSteps({ steps })
}
}).catch(err => {
const { response, code } = err
this.sending = false
Expand All @@ -194,11 +193,13 @@ class SyncService {
if (response?.status === 412) {
this.emit('error', { type: ERROR_TYPE.LOAD_ERROR, data: response })
} else if (response?.status === 403) {
if (!data.document) {
// TODO: is this really about sendable?
if (!sendable.document) {
// either the session is invalid or the document is read only.
logger.error('failed to write to document - not allowed')
this.emit('error', { type: ERROR_TYPE.PUSH_FORBIDDEN, data: {} })
}
// TODO: does response.data ever have a document? maybe for errors?
// Only emit conflict event if we have synced until the latest version
if (response.data.document?.currentVersion === this.version) {
this.emit('error', { type: ERROR_TYPE.PUSH_FAILURE, data: {} })
Expand All @@ -211,7 +212,7 @@ class SyncService {
})
}

_receiveSteps({ steps, document, sessions }) {
_receiveSteps({ steps, document = null, sessions = [] }) {
const awareness = sessions
.filter(s => s.lastContact > (Math.floor(Date.now() / 1000) - COLLABORATOR_DISCONNECT_TIME))
.filter(s => s.lastAwarenessMessage)
Expand Down Expand Up @@ -239,8 +240,7 @@ class SyncService {
this.lastStepPush = Date.now()
this.emit('sync', {
steps: newSteps,
// TODO: do we actually need to dig into the connection here?
document: this.#connection.document,
document,
version: this.version,
})
}
Expand Down