mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #1700 from sharelatex/bg-simplify-queue
simplify queuing code GitOrigin-RevId: 9c6ce66e9a3272dea28284d3cbf1dc65c9cbc825
This commit is contained in:
parent
9c5c6922b9
commit
f8066349c4
1 changed files with 11 additions and 21 deletions
|
@ -170,34 +170,24 @@ define(['utils/EventEmitter', 'libs/sharejs'], function(EventEmitter, ShareJs) {
|
|||
}
|
||||
|
||||
_processQueue() {
|
||||
while (this.queuedMessages.length > 0) {
|
||||
if (this.queuedMessages.length > 0) {
|
||||
nextAvailableVersion = this.queuedMessages[0].v
|
||||
if (nextAvailableVersion === this._doc.version) {
|
||||
// if the right version is on the queue, apply it
|
||||
if (nextAvailableVersion > this._doc.version) {
|
||||
// there are updates we still can't apply yet
|
||||
} else {
|
||||
// there's a version we can accept on the queue, apply it
|
||||
sl_console.log(
|
||||
`[processUpdate] taken from queue ${nextAvailableVersion}`
|
||||
)
|
||||
this.processUpdateFromServerInOrder(this.queuedMessages.shift())
|
||||
break
|
||||
} else if (nextAvailableVersion < this._doc.version) {
|
||||
// discard old updates if they are in the queue (since we are only
|
||||
// putting updates ahead of the current version in the queue this
|
||||
// shouldn't happen, but we handle it anyway for safety.)
|
||||
sl_console.log(
|
||||
`[processUpdate] discarded from queue ${nextAvailableVersion}`
|
||||
)
|
||||
this.queuedMessages.shift()
|
||||
} else {
|
||||
// there are updates we still can't apply yet
|
||||
break
|
||||
// clear the pending timer if the queue has now been cleared
|
||||
if (this.queuedMessages.length === 0 && this.queuedMessageTimer) {
|
||||
sl_console.log('[processUpdate] queue is empty, cleared timeout')
|
||||
clearTimeout(this.queuedMessageTimer)
|
||||
this.queuedMessageTimer = null
|
||||
}
|
||||
}
|
||||
}
|
||||
// clear the pending timer if the queue has now been cleared
|
||||
if (this.queuedMessages.length === 0 && this.queuedMessageTimer) {
|
||||
sl_console.log('[processUpdate] queue is empty, cleared timeout')
|
||||
clearTimeout(this.queuedMessageTimer)
|
||||
this.queuedMessageTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: This is the new method which reorders incoming updates if needed
|
||||
|
|
Loading…
Reference in a new issue