mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
Merge pull request #37 from sharelatex/bg-limit-ops-in-lock
put a limit on the number of ops per iteration
This commit is contained in:
commit
3d57976ef9
3 changed files with 9 additions and 6 deletions
|
@ -3,11 +3,13 @@ rclient = require("redis-sharelatex").createClient(Settings.redis.realtime)
|
||||||
Keys = Settings.redis.realtime.key_schema
|
Keys = Settings.redis.realtime.key_schema
|
||||||
logger = require('logger-sharelatex')
|
logger = require('logger-sharelatex')
|
||||||
|
|
||||||
|
MAX_OPS_PER_ITERATION = 8 # process a limited number of ops for safety
|
||||||
|
|
||||||
module.exports = RealTimeRedisManager =
|
module.exports = RealTimeRedisManager =
|
||||||
getPendingUpdatesForDoc : (doc_id, callback)->
|
getPendingUpdatesForDoc : (doc_id, callback)->
|
||||||
multi = rclient.multi()
|
multi = rclient.multi()
|
||||||
multi.lrange Keys.pendingUpdates({doc_id}), 0 , -1
|
multi.lrange Keys.pendingUpdates({doc_id}), 0, (MAX_OPS_PER_ITERATION-1)
|
||||||
multi.del Keys.pendingUpdates({doc_id})
|
multi.ltrim Keys.pendingUpdates({doc_id}), MAX_OPS_PER_ITERATION, -1
|
||||||
multi.exec (error, replys) ->
|
multi.exec (error, replys) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
jsonUpdates = replys[0]
|
jsonUpdates = replys[0]
|
||||||
|
|
|
@ -47,6 +47,7 @@ module.exports = UpdateManager =
|
||||||
profile = new Profiler("fetchAndApplyUpdates", {project_id, doc_id})
|
profile = new Profiler("fetchAndApplyUpdates", {project_id, doc_id})
|
||||||
RealTimeRedisManager.getPendingUpdatesForDoc doc_id, (error, updates) =>
|
RealTimeRedisManager.getPendingUpdatesForDoc doc_id, (error, updates) =>
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
|
logger.log {project_id: project_id, doc_id: doc_id, count: updates.length}, "processing updates"
|
||||||
if updates.length == 0
|
if updates.length == 0
|
||||||
return callback()
|
return callback()
|
||||||
profile.log("getPendingUpdatesForDoc")
|
profile.log("getPendingUpdatesForDoc")
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe "RealTimeRedisManager", ->
|
||||||
describe "getPendingUpdatesForDoc", ->
|
describe "getPendingUpdatesForDoc", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@rclient.lrange = sinon.stub()
|
@rclient.lrange = sinon.stub()
|
||||||
@rclient.del = sinon.stub()
|
@rclient.ltrim = sinon.stub()
|
||||||
|
|
||||||
describe "successfully", ->
|
describe "successfully", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -40,12 +40,12 @@ describe "RealTimeRedisManager", ->
|
||||||
|
|
||||||
it "should get the pending updates", ->
|
it "should get the pending updates", ->
|
||||||
@rclient.lrange
|
@rclient.lrange
|
||||||
.calledWith("PendingUpdates:#{@doc_id}", 0, -1)
|
.calledWith("PendingUpdates:#{@doc_id}", 0, 7)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should delete the pending updates", ->
|
it "should delete the pending updates", ->
|
||||||
@rclient.del
|
@rclient.ltrim
|
||||||
.calledWith("PendingUpdates:#{@doc_id}")
|
.calledWith("PendingUpdates:#{@doc_id}", 8, -1)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should call the callback with the updates", ->
|
it "should call the callback with the updates", ->
|
||||||
|
|
Loading…
Reference in a new issue