Procházet zdrojové kódy

For duplicate ops only send ack to submitting client

When a duplicate op is received, we only need to ack it to client
that sent it. Only that client is having trouble, and all other clients
will already have received it.
James Allen před 11 roky
rodič
revize
503b766dcc

+ 1 - 1
services/real-time/app/coffee/DocumentUpdaterController.coffee

@@ -24,7 +24,7 @@ module.exports = DocumentUpdaterController =
 			if client.id == update.meta.source
 			if client.id == update.meta.source
 				logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, "distributing update to sender"
 				logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, "distributing update to sender"
 				client.emit "otUpdateApplied", v: update.v, doc: update.doc
 				client.emit "otUpdateApplied", v: update.v, doc: update.doc
-			else
+			else if !update.dup # Duplicate ops should just be sent back to sending client for acknowledgement
 				logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, client_id: client.id, "distributing update to collaborator"
 				logger.log doc_id: doc_id, version: update.v, source: update.meta?.source, client_id: client.id, "distributing update to collaborator"
 				client.emit "otUpdateApplied", update
 				client.emit "otUpdateApplied", update
 
 

+ 35 - 16
services/real-time/test/unit/coffee/DocumentUpdaterControllerTests.coffee

@@ -68,24 +68,43 @@ describe "DocumentUpdaterController", ->
 				doc: @doc_id
 				doc: @doc_id
 			@io.sockets =
 			@io.sockets =
 				clients: sinon.stub().returns([@sourceClient, @otherClients...])
 				clients: sinon.stub().returns([@sourceClient, @otherClients...])
-			@EditorUpdatesController._applyUpdateFromDocumentUpdater @io, @doc_id, @update
-
-		it "should send a version bump to the source client", ->
-			@sourceClient.emit
-				.calledWith("otUpdateApplied", v: @version, doc: @doc_id)
-				.should.equal true
-
-		it "should get the clients connected to the document", ->
-			@io.sockets.clients
-				.calledWith(@doc_id)
-				.should.equal true
-
-		it "should send the full update to the other clients", ->
-			for client in @otherClients
-				client.emit
-					.calledWith("otUpdateApplied", @update)
+		
+		describe "normally", ->
+			beforeEach ->
+				@EditorUpdatesController._applyUpdateFromDocumentUpdater @io, @doc_id, @update
+
+			it "should send a version bump to the source client", ->
+				@sourceClient.emit
+					.calledWith("otUpdateApplied", v: @version, doc: @doc_id)
+					.should.equal true
+
+			it "should get the clients connected to the document", ->
+				@io.sockets.clients
+					.calledWith(@doc_id)
 					.should.equal true
 					.should.equal true
 
 
+			it "should send the full update to the other clients", ->
+				for client in @otherClients
+					client.emit
+						.calledWith("otUpdateApplied", @update)
+						.should.equal true
+		
+		describe "with a duplicate op", ->
+			beforeEach ->
+				@update.dup = true
+				@EditorUpdatesController._applyUpdateFromDocumentUpdater @io, @doc_id, @update
+			
+			it "should send a version bump to the source client as usual", ->
+				@sourceClient.emit
+					.calledWith("otUpdateApplied", v: @version, doc: @doc_id)
+					.should.equal true
+
+			it "should not send anything to the other clients (they've already had the op)", ->
+				for client in @otherClients
+					client.emit
+						.calledWith("otUpdateApplied")
+						.should.equal false
+
 	describe "_processErrorFromDocumentUpdater", ->
 	describe "_processErrorFromDocumentUpdater", ->
 		beforeEach ->
 		beforeEach ->
 			@clients = [new MockClient(), new MockClient()]
 			@clients = [new MockClient(), new MockClient()]