mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-14 07:14:37 +00:00
make peekLastUpdate alway return lastVersion when available
This commit is contained in:
parent
933b6c50e7
commit
5153ed8217
4 changed files with 25 additions and 21 deletions
services/track-changes
app/coffee
test/unit/coffee
|
@ -18,7 +18,7 @@ module.exports = MongoManager =
|
|||
|
||||
peekLastCompressedUpdate: (doc_id, callback = (error, update, version) ->) ->
|
||||
# under normal use we pass back the last update as
|
||||
# callback(null,update).
|
||||
# callback(null,update,version).
|
||||
#
|
||||
# when we have an existing last update but want to force a new one
|
||||
# to start, we pass it back as callback(null,null,version), just
|
||||
|
@ -26,17 +26,18 @@ module.exports = MongoManager =
|
|||
MongoManager.getLastCompressedUpdate doc_id, (error, update) ->
|
||||
return callback(error) if error?
|
||||
if update?
|
||||
if update.inS3?
|
||||
# we want to force a new update, but ensure that it is
|
||||
# consistent with the version of the existing one in S3
|
||||
return callback null, null, update.v
|
||||
else if update.broken
|
||||
if update.broken
|
||||
# the update is marked as broken so we will force a new op
|
||||
return callback null, null
|
||||
else if update.pack?
|
||||
return callback null, update, update.pack[0]?.v
|
||||
else
|
||||
return callback null, update
|
||||
return callback null, update, update.v
|
||||
else
|
||||
callback null, null
|
||||
MongoManager.getArchivedDocStatus doc_id, (error, status) ->
|
||||
return callback(error) if error?
|
||||
return callback(null, null, status.lastVersion) if status?.inS3? and status?.lastVersion?
|
||||
callback null, null
|
||||
|
||||
insertCompressedUpdates: (project_id, doc_id, updates, temporary, callback = (error) ->) ->
|
||||
jobs = []
|
||||
|
@ -152,6 +153,9 @@ module.exports = MongoManager =
|
|||
db.docHistoryStats.ensureIndex { doc_id: 1 }, { background: true }
|
||||
db.docHistoryStats.ensureIndex { updates: -1, doc_id: 1 }, { background: true }
|
||||
|
||||
getArchivedDocStatus: (doc_id, callback)->
|
||||
db.docHistoryStats.findOne {doc_id: ObjectId(doc_id.toString()), inS3: {$exists:true}}, {inS3: true, lastVersion: true}, callback
|
||||
|
||||
getDocChangesCount: (doc_id, callback)->
|
||||
db.docHistory.count { doc_id : ObjectId(doc_id.toString()), inS3 : { $exists : false }}, callback
|
||||
|
||||
|
|
|
@ -17,17 +17,13 @@ module.exports = UpdatesManager =
|
|||
return callback()
|
||||
|
||||
MongoManager.peekLastCompressedUpdate doc_id, (error, lastCompressedUpdate, lastVersion) ->
|
||||
# lastCompressedUpdate is the most recent update in Mongo.
|
||||
# lastCompressedUpdate is the most recent update in Mongo, and
|
||||
# lastVersion is its sharejs version number.
|
||||
#
|
||||
# The peekLastCompressedUpdate method may pass it back as 'null'
|
||||
# to force the start of a new compressed update, even when there
|
||||
# was a previous compressed update in Mongo. In this case it
|
||||
# passes back the lastVersion from the update to check
|
||||
# consistency.
|
||||
|
||||
# when lastVersion is not provided, default to lastCompressedUpdate.v
|
||||
lastVersion ?= lastCompressedUpdate?.v
|
||||
|
||||
# The peekLastCompressedUpdate method may pass the update back
|
||||
# as 'null' (for example if the previous compressed update has
|
||||
# been archived). In this case it can still pass back the
|
||||
# lastVersion from the update to allow us to check consistency.
|
||||
return callback(error) if error?
|
||||
|
||||
# Ensure that raw updates start where lastVersion left off
|
||||
|
|
|
@ -57,6 +57,8 @@ describe "MongoManager", ->
|
|||
describe "peekLastCompressedUpdate", ->
|
||||
describe "when there is no last update", ->
|
||||
beforeEach ->
|
||||
@db.docHistoryStats = {}
|
||||
@db.docHistoryStats.findOne = sinon.stub().callsArgWith(2, null, null)
|
||||
@MongoManager.getLastCompressedUpdate = sinon.stub().callsArgWith(1, null, null)
|
||||
@MongoManager.peekLastCompressedUpdate @doc_id, @callback
|
||||
|
||||
|
@ -84,8 +86,10 @@ describe "MongoManager", ->
|
|||
|
||||
describe "when there is a last update in S3", ->
|
||||
beforeEach ->
|
||||
@update = { _id: Object(), v: 12345, inS3: true }
|
||||
@MongoManager.getLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @update)
|
||||
@update = { _id: Object(), v: 12345}
|
||||
@db.docHistoryStats = {}
|
||||
@db.docHistoryStats.findOne = sinon.stub().callsArgWith(2, null, {inS3:true, lastVersion: @update.v})
|
||||
@MongoManager.getLastCompressedUpdate = sinon.stub().callsArgWith(1, null)
|
||||
@MongoManager.peekLastCompressedUpdate @doc_id, @callback
|
||||
|
||||
it "should get the last update", ->
|
||||
|
|
|
@ -69,7 +69,7 @@ describe "UpdatesManager", ->
|
|||
@lastCompressedUpdate = { v: 11, op: "compressed-op-11" }
|
||||
@compressedUpdates = [ { v: 12, op: "compressed-op-11+12" }, { v: 13, op: "compressed-op-12" } ]
|
||||
|
||||
@MongoManager.peekLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @lastCompressedUpdate)
|
||||
@MongoManager.peekLastCompressedUpdate = sinon.stub().callsArgWith(1, null, @lastCompressedUpdate, @lastCompressedUpdate.v)
|
||||
@MongoManager.modifyCompressedUpdate = sinon.stub().callsArg(2)
|
||||
@MongoManager.insertCompressedUpdates = sinon.stub().callsArg(4)
|
||||
@UpdateCompressor.compressRawUpdates = sinon.stub().returns(@compressedUpdates)
|
||||
|
|
Loading…
Add table
Reference in a new issue