Merge pull request #13 from sharelatex/ja-remove-multi-call

Remove multi call to make compatible with redis-cluster
This commit is contained in:
James Allen 2017-05-12 13:58:07 +01:00 committed by GitHub
commit 5cd5b7e110
3 changed files with 7 additions and 27 deletions

View file

@ -55,10 +55,8 @@ module.exports = DocumentUpdaterManager =
queueChange: (project_id, doc_id, change, callback = ()->)->
jsonChange = JSON.stringify change
doc_key = "#{project_id}:#{doc_id}"
multi = rclient.multi()
multi.rpush Keys.pendingUpdates({doc_id}), jsonChange
multi.sadd "DocsWithPendingUpdates", doc_key
multi.rpush "pending-updates-list", doc_key
multi.exec (error) ->
# Push onto pendingUpdates for doc_id first, because once the doc updater
# gets an entry on pending-updates-list, it starts processing.
rclient.rpush Keys.pendingUpdates({doc_id}), jsonChange, (error) ->
return callback(error) if error?
callback()
rclient.rpush "pending-updates-list", doc_key, callback

View file

@ -46,11 +46,6 @@ describe "applyOtUpdate", ->
rclient.lrange "pending-updates-list", 0, -1, (error, [doc_id]) =>
doc_id.should.equal "#{@project_id}:#{@doc_id}"
done()
it "should add the doc to the pending updates set in redis", (done) ->
rclient.sismember "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", (error, isMember) =>
isMember.should.equal 1
done()
it "should push the update into redis", (done) ->
rclient.lrange "PendingUpdates:#{@doc_id}", 0, -1, (error, [update]) =>
@ -145,11 +140,6 @@ describe "applyOtUpdate", ->
rclient.lrange "pending-updates-list", 0, -1, (error, [doc_id]) =>
doc_id.should.equal "#{@project_id}:#{@doc_id}"
done()
it "should add the doc to the pending updates set in redis", (done) ->
rclient.sismember "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", (error, isMember) =>
isMember.should.equal 1
done()
it "should push the update into redis", (done) ->
rclient.lrange "PendingUpdates:#{@doc_id}", 0, -1, (error, [update]) =>

View file

@ -123,10 +123,7 @@ describe 'DocumentUpdaterManager', ->
"range":{"start":{"row":2,"column":2},"end":{"row":2,"column":3}},
"text":"e"
}
@rclient.multi = sinon.stub().returns @rclient
@rclient.exec = sinon.stub().callsArg(0)
@rclient.rpush = sinon.stub()
@rclient.sadd = sinon.stub()
@rclient.rpush = sinon.stub().yields()
@callback = sinon.stub()
describe "successfully", ->
@ -143,14 +140,9 @@ describe 'DocumentUpdaterManager', ->
.calledWith("pending-updates-list", "#{@project_id}:#{@doc_id}")
.should.equal true
it "should push the doc id into the pending updates set", ->
@rclient.sadd
.calledWith("DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}")
.should.equal true
describe "with error connecting to redis during exec", ->
describe "with error talking to redis during rpush", ->
beforeEach ->
@rclient.exec = sinon.stub().callsArgWith(0, new Error("something went wrong"))
@rclient.rpush = sinon.stub().yields(new Error("something went wrong"))
@DocumentUpdaterManager.queueChange(@project_id, @doc_id, @change, @callback)
it "should return an error", ->