put a limit on the number of ops per iteration

This commit is contained in:
Brian Gough 2017-05-12 13:11:04 +01:00
parent 42225ffc45
commit d4a8d88750
2 changed files with 8 additions and 6 deletions

View file

@ -3,11 +3,13 @@ rclient = require("redis-sharelatex").createClient(Settings.redis.realtime)
Keys = Settings.redis.realtime.key_schema
logger = require('logger-sharelatex')
MAX_OPS_PER_ITERATION = 8 # process a limited number of ops for safety
module.exports = RealTimeRedisManager =
getPendingUpdatesForDoc : (doc_id, callback)->
multi = rclient.multi()
multi.lrange Keys.pendingUpdates({doc_id}), 0 , -1
multi.del Keys.pendingUpdates({doc_id})
multi.lrange Keys.pendingUpdates({doc_id}), 0, (MAX_OPS_PER_ITERATION-1)
multi.ltrim Keys.pendingUpdates({doc_id}), MAX_OPS_PER_ITERATION, -1
multi.exec (error, replys) ->
return callback(error) if error?
jsonUpdates = replys[0]

View file

@ -26,7 +26,7 @@ describe "RealTimeRedisManager", ->
describe "getPendingUpdatesForDoc", ->
beforeEach ->
@rclient.lrange = sinon.stub()
@rclient.del = sinon.stub()
@rclient.ltrim = sinon.stub()
describe "successfully", ->
beforeEach ->
@ -40,12 +40,12 @@ describe "RealTimeRedisManager", ->
it "should get the pending updates", ->
@rclient.lrange
.calledWith("PendingUpdates:#{@doc_id}", 0, -1)
.calledWith("PendingUpdates:#{@doc_id}", 0, 7)
.should.equal true
it "should delete the pending updates", ->
@rclient.del
.calledWith("PendingUpdates:#{@doc_id}")
@rclient.ltrim
.calledWith("PendingUpdates:#{@doc_id}", 8, -1)
.should.equal true
it "should call the callback with the updates", ->