mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 05:32:48 +00:00
Move check of zero length op array up a level
This commit is contained in:
parent
993aab7a78
commit
5ce15c4d60
4 changed files with 15 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue