mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
Ensure version is still returned from redis
This commit is contained in:
parent
b13f70eadb
commit
dfd3ec993b
4 changed files with 13 additions and 13 deletions
|
@ -44,9 +44,11 @@ module.exports = DocOpsManager =
|
|||
callback null, ops
|
||||
|
||||
pushDocOp: (project_id, doc_id, op, callback = (error) ->) ->
|
||||
RedisManager.pushDocOp doc_id, op, (error) ->
|
||||
RedisManager.pushDocOp doc_id, op, (error, version) ->
|
||||
return callback(error) if error?
|
||||
RedisManager.pushUncompressedHistoryOp doc_id, op, callback
|
||||
RedisManager.pushUncompressedHistoryOp doc_id, op, (error) ->
|
||||
return callback(error) if error?
|
||||
callback null, version
|
||||
|
||||
_ensureOpsAreLoaded: (project_id, doc_id, backToVersion, callback = (error) ->) ->
|
||||
RedisManager.getDocVersion doc_id, (error, redisVersion) ->
|
||||
|
|
|
@ -4,6 +4,7 @@ DocumentManager = require "./DocumentManager"
|
|||
RedisManager = require "./RedisManager"
|
||||
DocOpsManager = require "./DocOpsManager"
|
||||
Errors = require "./Errors"
|
||||
logger = require "logger-sharelatex"
|
||||
|
||||
module.exports = ShareJsDB =
|
||||
getOps: (doc_key, start, end, callback) ->
|
||||
|
@ -29,9 +30,9 @@ module.exports = ShareJsDB =
|
|||
if version == opData.v + 1
|
||||
callback()
|
||||
else
|
||||
# The document has been corrupted by the change. For now, throw an exception.
|
||||
# Later, rebuild the snapshot.
|
||||
callback "Version mismatch in db.append. '#{doc_id}' is corrupted."
|
||||
error = new Error("Version mismatch. '#{doc_id}' is corrupted.")
|
||||
logger.error err: error, doc_id: doc_id, project_id: project_id, opVersion: opData.v, expectedVersion: version, "doc is corrupt"
|
||||
callback error
|
||||
|
||||
getSnapshot: (doc_key, callback) ->
|
||||
[project_id, doc_id] = Keys.splitProjectIdAndDocId(doc_key)
|
||||
|
|
|
@ -309,7 +309,7 @@ describe "DocOpsManager", ->
|
|||
describe "pushDocOp", ->
|
||||
beforeEach ->
|
||||
@op = "mock-op"
|
||||
@RedisManager.pushDocOp = sinon.stub().callsArg(2)
|
||||
@RedisManager.pushDocOp = sinon.stub().callsArgWith(2, null, @version = 42)
|
||||
@RedisManager.pushUncompressedHistoryOp = sinon.stub().callsArg(2)
|
||||
@DocOpsManager.pushDocOp @project_id, @doc_id, @op, @callback
|
||||
|
||||
|
@ -323,7 +323,7 @@ describe "DocOpsManager", ->
|
|||
.calledWith(@doc_id, @op)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
it "should call the callback with the version", ->
|
||||
@callback.calledWith(null, @version).should.equal true
|
||||
|
||||
|
||||
|
|
|
@ -26,11 +26,8 @@ describe "ShareJsDB.writeOps", ->
|
|||
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
||||
|
||||
it "should write the op to redis", ->
|
||||
op =
|
||||
op: @opData.op
|
||||
meta: @opData.meta
|
||||
@DocOpsManager.pushDocOp
|
||||
.calledWith(@project_id, @doc_id, op)
|
||||
.calledWith(@project_id, @doc_id, @opData)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback without an error", ->
|
||||
|
@ -46,7 +43,7 @@ describe "ShareJsDB.writeOps", ->
|
|||
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
||||
|
||||
it "should call the callback with an error", ->
|
||||
@callback.calledWith(sinon.match.string).should.equal true
|
||||
@callback.calledWith(new Error()).should.equal true
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue