浏览代码

Add in /doc/<doc-id>/flush endpoint

James Allen 12 年之前
父节点
当前提交
45fe6978af

+ 6 - 3
services/track-changes/app.coffee

@@ -6,14 +6,17 @@ HttpController = require "./app/js/HttpController"
 express = require "express"
 express = require "express"
 app = express()
 app = express()
 
 
-app.post "/doc/:doc_id/history", express.bodyParser(), HttpController.appendUpdates
+app.post "/doc/:doc_id/flush", HttpController.flushUpdatesWithLock
 
 
 app.use (error, req, res, next) ->
 app.use (error, req, res, next) ->
 	logger.error err: error, "an internal error occured"
 	logger.error err: error, "an internal error occured"
 	req.send 500
 	req.send 500
 
 
-app.listen (Settings.port ||= 3014), (error) ->
+port = Settings.internal?.history?.port or 3014
+host = Settings.internal?.history?.host or "localhost"
+app.listen port, host, (error) ->
 	if error?
 	if error?
 		logger.error err: error, "could not start history server"
 		logger.error err: error, "could not start history server"
-	logger.log "history api listening on port 3014"
+	else
+		logger.log "history api listening on http://#{host}:#{port}"
 
 

+ 3 - 5
services/track-changes/app/coffee/HttpController.coffee

@@ -2,11 +2,9 @@ HistoryManager = require "./HistoryManager"
 logger = require "logger-sharelatex"
 logger = require "logger-sharelatex"
 
 
 module.exports = HttpController =
 module.exports = HttpController =
-	appendUpdates: (req, res, next = (error) ->) ->
+	flushUpdatesWithLock: (req, res, next = (error) ->) ->
 		doc_id = req.params.doc_id
 		doc_id = req.params.doc_id
-		docOps  = req.body.docOps
-		version = req.body.version
-		logger.log doc_id: doc_id, version: version, "compressing doc history"
-		HistoryManager.compressAndSaveRawUpdates doc_id, docOps, (error) ->
+		logger.log doc_id: doc_id, "compressing doc history"
+		HistoryManager.processUncompressedUpdatesWithLock doc_id, (error) ->
 			return next(error) if error?
 			return next(error) if error?
 			res.send 204
 			res.send 204

+ 6 - 9
services/track-changes/test/unit/coffee/HttpController/HttpControllerTests.coffee

@@ -14,22 +14,19 @@ describe "HttpController", ->
 		@version = 42
 		@version = 42
 		@next = sinon.stub()
 		@next = sinon.stub()
 
 
-	describe "appendUpdates", ->
+	describe "flushUpdatesWithLock", ->
 		beforeEach ->
 		beforeEach ->
 			@req =
 			@req =
 				params:
 				params:
 					doc_id: @doc_id
 					doc_id: @doc_id
-				body:
-					docOps: @docOps = ["mock-ops"]
-					version: @version
 			@res =
 			@res =
 				send: sinon.stub()
 				send: sinon.stub()
-			@HistoryManager.compressAndSaveRawUpdates = sinon.stub().callsArg(2)
-			@HttpController.appendUpdates @req, @res, @next
+			@HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
+			@HttpController.flushUpdatesWithLock @req, @res, @next
 
 
-		it "should append the updates", ->
-			@HistoryManager.compressAndSaveRawUpdates
-				.calledWith(@doc_id, @docOps)
+		it "should process the updates", ->
+			@HistoryManager.processUncompressedUpdatesWithLock
+				.calledWith(@doc_id)
 				.should.equal true
 				.should.equal true
 
 
 		it "should return a success code", ->
 		it "should return a success code", ->