mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 23:04:15 -05:00
fix update-in-place bug for array ops
This commit is contained in:
parent
11be8c3733
commit
be2136de7c
3 changed files with 28 additions and 1 deletions
|
@ -56,6 +56,10 @@ module.exports = UpdateCompressor =
|
|||
return concattedUpdates
|
||||
|
||||
compressRawUpdates: (lastPreviousUpdate, rawUpdates) ->
|
||||
if lastPreviousUpdate?.op?.length > 1
|
||||
# if the last previous update was an array op, don't compress onto it.
|
||||
# The avoids cases where array length changes but version number doesn't
|
||||
return [lastPreviousUpdate].concat UpdateCompressor.compressRawUpdates(null,rawUpdates)
|
||||
if lastPreviousUpdate?
|
||||
rawUpdates = [lastPreviousUpdate].concat(rawUpdates)
|
||||
updates = UpdateCompressor.convertToSingleOpUpdates(rawUpdates)
|
||||
|
|
|
@ -7,6 +7,7 @@ UpdateTrimmer = require "./UpdateTrimmer"
|
|||
logger = require "logger-sharelatex"
|
||||
async = require "async"
|
||||
DocArchiveManager = require "./DocArchiveManager"
|
||||
_ = require "underscore"
|
||||
|
||||
module.exports = UpdatesManager =
|
||||
compressAndSaveRawUpdates: (project_id, doc_id, rawUpdates, temporary, callback = (error) ->) ->
|
||||
|
@ -50,7 +51,7 @@ module.exports = UpdatesManager =
|
|||
# compress them together with the new ones
|
||||
[firstUpdate, additionalUpdates...] = compressedUpdates
|
||||
|
||||
if firstUpdate.v == lastCompressedUpdate.v
|
||||
if firstUpdate.v == lastCompressedUpdate.v and _.isEqual(firstUpdate, lastCompressedUpdate)
|
||||
# first update version hasn't changed, skip it and insert remaining updates
|
||||
# this is an optimisation, we could update the existing op with itself
|
||||
updateToModify = null
|
||||
|
|
|
@ -304,3 +304,25 @@ describe "UpdateCompressor", ->
|
|||
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
|
||||
v: 43
|
||||
}]
|
||||
|
||||
describe "compressRawUpdates", ->
|
||||
describe "merging in-place with an array op", ->
|
||||
it "should not change the existing last updates", ->
|
||||
expect(@UpdateCompressor.compressRawUpdates {
|
||||
op: [ {"p":1000,"d":"hello"}, {"p":1000,"i":"HELLO()"} ]
|
||||
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
|
||||
v: 42
|
||||
}, [{
|
||||
op: [{ p: 1006, i: "WORLD" }]
|
||||
meta: ts: @ts2, user_id: @user_id
|
||||
v: 43
|
||||
}])
|
||||
.to.deep.equal [{
|
||||
op: [{"p":1000,"d":"hello"}, {"p":1000,"i":"HELLO()"} ]
|
||||
meta: start_ts: @ts1, end_ts: @ts1, user_id: @user_id
|
||||
v: 42
|
||||
},{
|
||||
op: [{"p":1006,"i":"WORLD"}]
|
||||
meta: start_ts: @ts2, end_ts: @ts2, user_id: @user_id
|
||||
v: 43
|
||||
}]
|
||||
|
|
Loading…
Reference in a new issue