mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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
|
callback null, ops
|
||||||
|
|
||||||
pushDocOp: (project_id, doc_id, op, callback = (error) ->) ->
|
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?
|
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) ->) ->
|
_ensureOpsAreLoaded: (project_id, doc_id, backToVersion, callback = (error) ->) ->
|
||||||
RedisManager.getDocVersion doc_id, (error, redisVersion) ->
|
RedisManager.getDocVersion doc_id, (error, redisVersion) ->
|
||||||
|
|
|
@ -4,6 +4,7 @@ DocumentManager = require "./DocumentManager"
|
||||||
RedisManager = require "./RedisManager"
|
RedisManager = require "./RedisManager"
|
||||||
DocOpsManager = require "./DocOpsManager"
|
DocOpsManager = require "./DocOpsManager"
|
||||||
Errors = require "./Errors"
|
Errors = require "./Errors"
|
||||||
|
logger = require "logger-sharelatex"
|
||||||
|
|
||||||
module.exports = ShareJsDB =
|
module.exports = ShareJsDB =
|
||||||
getOps: (doc_key, start, end, callback) ->
|
getOps: (doc_key, start, end, callback) ->
|
||||||
|
@ -29,9 +30,9 @@ module.exports = ShareJsDB =
|
||||||
if version == opData.v + 1
|
if version == opData.v + 1
|
||||||
callback()
|
callback()
|
||||||
else
|
else
|
||||||
# The document has been corrupted by the change. For now, throw an exception.
|
error = new Error("Version mismatch. '#{doc_id}' is corrupted.")
|
||||||
# Later, rebuild the snapshot.
|
logger.error err: error, doc_id: doc_id, project_id: project_id, opVersion: opData.v, expectedVersion: version, "doc is corrupt"
|
||||||
callback "Version mismatch in db.append. '#{doc_id}' is corrupted."
|
callback error
|
||||||
|
|
||||||
getSnapshot: (doc_key, callback) ->
|
getSnapshot: (doc_key, callback) ->
|
||||||
[project_id, doc_id] = Keys.splitProjectIdAndDocId(doc_key)
|
[project_id, doc_id] = Keys.splitProjectIdAndDocId(doc_key)
|
||||||
|
|
|
@ -309,7 +309,7 @@ describe "DocOpsManager", ->
|
||||||
describe "pushDocOp", ->
|
describe "pushDocOp", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@op = "mock-op"
|
@op = "mock-op"
|
||||||
@RedisManager.pushDocOp = sinon.stub().callsArg(2)
|
@RedisManager.pushDocOp = sinon.stub().callsArgWith(2, null, @version = 42)
|
||||||
@RedisManager.pushUncompressedHistoryOp = sinon.stub().callsArg(2)
|
@RedisManager.pushUncompressedHistoryOp = sinon.stub().callsArg(2)
|
||||||
@DocOpsManager.pushDocOp @project_id, @doc_id, @op, @callback
|
@DocOpsManager.pushDocOp @project_id, @doc_id, @op, @callback
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ describe "DocOpsManager", ->
|
||||||
.calledWith(@doc_id, @op)
|
.calledWith(@doc_id, @op)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should call the callback", ->
|
it "should call the callback with the version", ->
|
||||||
@callback.called.should.equal true
|
@callback.calledWith(null, @version).should.equal true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,8 @@ describe "ShareJsDB.writeOps", ->
|
||||||
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
||||||
|
|
||||||
it "should write the op to redis", ->
|
it "should write the op to redis", ->
|
||||||
op =
|
|
||||||
op: @opData.op
|
|
||||||
meta: @opData.meta
|
|
||||||
@DocOpsManager.pushDocOp
|
@DocOpsManager.pushDocOp
|
||||||
.calledWith(@project_id, @doc_id, op)
|
.calledWith(@project_id, @doc_id, @opData)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should call the callback without an error", ->
|
it "should call the callback without an error", ->
|
||||||
|
@ -46,7 +43,7 @@ describe "ShareJsDB.writeOps", ->
|
||||||
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
@ShareJsDB.writeOp @doc_key, @opData, @callback
|
||||||
|
|
||||||
it "should call the callback with an error", ->
|
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