Эх сурвалжийг харах

Remove multi call to make compatible with redis-cluster

James Allen 9 жил өмнө
parent
commit
a8917b933f

+ 4 - 6
services/real-time/app/coffee/DocumentUpdaterManager.coffee

@@ -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

+ 0 - 10
services/real-time/test/acceptance/coffee/ApplyUpdateTests.coffee

@@ -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]) =>

+ 3 - 11
services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee

@@ -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", ->