Skip to content

Commit 1702eee

Browse files
committed
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 <max@nextcloud.com>
1 parent b31e1e5 commit 1702eee

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/components/Editor.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ export default {
592592
this.$nextTick(() => {
593593
this.emit('sync-service:sync')
594594
})
595-
this.document = document
595+
if (document) {
596+
this.document = document
597+
}
596598
},
597599
598600
onError({ type, data }) {

src/services/SyncService.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,18 @@ class SyncService {
171171
this.sending = true
172172
clearInterval(this.#sendIntervalId)
173173
this.#sendIntervalId = null
174-
const data = getSendable()
175-
if (data.steps.length > 0) {
174+
const sendable = getSendable()
175+
if (sendable.steps.length > 0) {
176176
this.emit('stateChange', { dirty: true })
177177
}
178-
return this.#connection.push(data)
178+
return this.#connection.push(sendable)
179179
.then((response) => {
180+
const { steps } = response.data
180181
this.pushError = 0
181182
this.sending = false
182-
this.emit('sync', {
183-
steps: [],
184-
document: this.#connection.document,
185-
version: this.version,
186-
})
183+
if (steps?.length > 0) {
184+
this._receiveSteps({ steps })
185+
}
187186
}).catch(err => {
188187
const { response, code } = err
189188
this.sending = false
@@ -194,11 +193,13 @@ class SyncService {
194193
if (response?.status === 412) {
195194
this.emit('error', { type: ERROR_TYPE.LOAD_ERROR, data: response })
196195
} else if (response?.status === 403) {
197-
if (!data.document) {
196+
// TODO: is this really about sendable?
197+
if (!sendable.document) {
198198
// either the session is invalid or the document is read only.
199199
logger.error('failed to write to document - not allowed')
200200
this.emit('error', { type: ERROR_TYPE.PUSH_FORBIDDEN, data: {} })
201201
}
202+
// TODO: does response.data ever have a document? maybe for errors?
202203
// Only emit conflict event if we have synced until the latest version
203204
if (response.data.document?.currentVersion === this.version) {
204205
this.emit('error', { type: ERROR_TYPE.PUSH_FAILURE, data: {} })
@@ -211,7 +212,7 @@ class SyncService {
211212
})
212213
}
213214

214-
_receiveSteps({ steps, document, sessions }) {
215+
_receiveSteps({ steps, document = null, sessions = [] }) {
215216
const awareness = sessions
216217
.filter(s => s.lastContact > (Math.floor(Date.now() / 1000) - COLLABORATOR_DISCONNECT_TIME))
217218
.filter(s => s.lastAwarenessMessage)
@@ -239,8 +240,7 @@ class SyncService {
239240
this.lastStepPush = Date.now()
240241
this.emit('sync', {
241242
steps: newSteps,
242-
// TODO: do we actually need to dig into the connection here?
243-
document: this.#connection.document,
243+
document,
244244
version: this.version,
245245
})
246246
}

0 commit comments

Comments
 (0)