mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Move check of zero length op array up a level
This commit is contained in:
@@ -22,7 +22,9 @@ module.exports = TrackChangesManager =
|
||||
return callback(error)
|
||||
|
||||
FLUSH_EVERY_N_OPS: 50
|
||||
pushUncompressedHistoryOps: (project_id, doc_id, ops, callback = (error) ->) ->
|
||||
pushUncompressedHistoryOps: (project_id, doc_id, ops = [], callback = (error) ->) ->
|
||||
if ops.length == 0
|
||||
return callback()
|
||||
WebRedisManager.pushUncompressedHistoryOps project_id, doc_id, ops, (error, length) ->
|
||||
return callback(error) if error?
|
||||
# We want to flush every 50 ops, i.e. 50, 100, 150, etc
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = WebRedisManager =
|
||||
|
||||
pushUncompressedHistoryOps: (project_id, doc_id, ops = [], callback = (error, length) ->) ->
|
||||
if ops.length == 0
|
||||
return callback(null, 0)
|
||||
return callback(new Error("cannot push no ops")) # This should never be called with no ops, but protect against a redis error if we sent an empty array to rpush
|
||||
jsonOps = ops.map (op) -> JSON.stringify op
|
||||
async.parallel [
|
||||
(cb) -> rclient.rpush "UncompressedHistoryOps:#{doc_id}", jsonOps..., cb
|
||||
|
||||
+9
@@ -100,4 +100,13 @@ describe "TrackChangesManager", ->
|
||||
"error flushing doc to track changes api"
|
||||
)
|
||||
.should.equal true
|
||||
|
||||
describe "with no ops", ->
|
||||
beforeEach ->
|
||||
@WebRedisManager.pushUncompressedHistoryOps = sinon.stub().callsArgWith(3, null, 1)
|
||||
@TrackChangesManager.pushUncompressedHistoryOps @project_id, @doc_id, [], @callback
|
||||
|
||||
it "should not call WebRedisManager.pushUncompressedHistoryOps", ->
|
||||
@WebRedisManager.pushUncompressedHistoryOps.called.should.equal false
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -111,5 +111,5 @@ describe "WebRedisManager", ->
|
||||
.called
|
||||
.should.equal false
|
||||
|
||||
it "should call the callback with the length", ->
|
||||
@callback.calledWith(null, 0).should.equal true
|
||||
it "should call the callback with an error", ->
|
||||
@callback.calledWith(new Error("cannot push no ops")).should.equal true
|
||||
|
||||
Reference in New Issue
Block a user