Procházet zdrojové kódy

change getProjectDocs endpoint from GET to POST

also note that it flushes docs if they are considered old (i.e. not
recently flushed)
Brian Gough před 9 roky
rodič
revize
7cbb3e7af8

+ 1 - 1
services/document-updater/app.coffee

@@ -38,7 +38,7 @@ app.param 'doc_id', (req, res, next, doc_id) ->
 		next new Error("invalid doc id")
 
 app.get    '/project/:project_id/doc/:doc_id',                          HttpController.getDoc
-app.get    '/project/:project_id/doc',                                  HttpController.getProjectDocs
+app.post   '/project/:project_id/get_and_flush_if_old',                 HttpController.getProjectDocsAndFlushIfOld
 app.post   '/project/:project_id/clearState',                           HttpController.clearProjectState
 app.post   '/project/:project_id/doc/:doc_id',                          HttpController.setDoc
 app.post   '/project/:project_id/doc/:doc_id/flush',                    HttpController.flushDocIfLoaded

+ 2 - 2
services/document-updater/app/coffee/HttpController.coffee

@@ -37,7 +37,7 @@ module.exports = HttpController =
 			size += (line.length + 1)
 		return size
 
-	getProjectDocs: (req, res, next = (error) ->) ->
+	getProjectDocsAndFlushIfOld: (req, res, next = (error) ->) ->
 		project_id = req.params.project_id
 		projectStateHash = req.query?.state
 		# exclude is string of existing docs "id:version,id:version,..."
@@ -49,7 +49,7 @@ module.exports = HttpController =
 			[id,version] = item?.split(':')
 			excludeVersions[id] = version
 		logger.log {project_id: project_id, projectStateHash: projectStateHash, excludeVersions: excludeVersions}, "excluding versions"
-		ProjectManager.getProjectDocs project_id, projectStateHash, excludeVersions, (error, result) ->
+		ProjectManager.getProjectDocsAndFlushIfOld project_id, projectStateHash, excludeVersions, (error, result) ->
 			timer.done()
 			if error instanceof Errors.ProjectStateChangedError
 				res.send 409 # conflict

+ 4 - 4
services/document-updater/app/coffee/ProjectManager.coffee

@@ -58,15 +58,15 @@ module.exports = ProjectManager =
 				else
 					callback(null)
 
-	getProjectDocs: (project_id, projectStateHash, excludeVersions = {}, _callback = (error, docs) ->) ->
-		timer = new Metrics.Timer("projectManager.getProjectDocs")
+	getProjectDocsAndFlushIfOld: (project_id, projectStateHash, excludeVersions = {}, _callback = (error, docs) ->) ->
+		timer = new Metrics.Timer("projectManager.getProjectDocsAndFlushIfOld")
 		callback = (args...) ->
 			timer.done()
 			_callback(args...)
 
 		RedisManager.checkOrSetProjectState project_id, projectStateHash, (error, projectStateChanged) ->
 			if error?
-				logger.error err: error, project_id: project_id, "error getting/setting project state in getProjectDocs"
+				logger.error err: error, project_id: project_id, "error getting/setting project state in getProjectDocsAndFlushIfOld"
 				return callback(error)
 			# we can't return docs if project structure has changed
 			if projectStateChanged
@@ -83,7 +83,7 @@ module.exports = ProjectManager =
 							# get the doc lines from redis
 							DocumentManager.getDocAndFlushIfOldWithLock project_id, doc_id, (err, lines, version) ->
 								if err?
-									logger.error err:err, project_id: project_id, doc_id: doc_id, "error getting project doc lines in getProjectDocs"
+									logger.error err:err, project_id: project_id, doc_id: doc_id, "error getting project doc lines in getProjectDocsAndFlushIfOld"
 									return cb(err)
 								doc = {_id:doc_id, lines:lines, v:version} # create a doc object to return
 								cb(null, doc)

+ 8 - 8
services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee

@@ -435,7 +435,7 @@ describe "HttpController", ->
 					.calledWith(new Error("oops"))
 					.should.equal true
 
-	describe "getProjectDocs", ->
+	describe "getProjectDocsAndFlushIfOld", ->
 		beforeEach ->
 			@state = "01234567890abcdef"
 			@docs = [{_id: "1234", lines: "hello", v: 23}, {_id: "4567", lines: "world", v: 45}]
@@ -447,11 +447,11 @@ describe "HttpController", ->
 
 		describe "successfully", ->
 			beforeEach ->
-				@ProjectManager.getProjectDocs = sinon.stub().callsArgWith(3,null, @docs)
-				@HttpController.getProjectDocs(@req, @res, @next)
+				@ProjectManager.getProjectDocsAndFlushIfOld = sinon.stub().callsArgWith(3,null, @docs)
+				@HttpController.getProjectDocsAndFlushIfOld(@req, @res, @next)
 
 			it "should get docs from the project manager", ->
-				@ProjectManager.getProjectDocs
+				@ProjectManager.getProjectDocsAndFlushIfOld
 					.calledWith(@project_id, @state, {})
 					.should.equal true
 
@@ -475,8 +475,8 @@ describe "HttpController", ->
 
 		describe "when there is a conflict", ->
 			beforeEach ->
-				@ProjectManager.getProjectDocs = sinon.stub().callsArgWith(3, new Errors.ProjectStateChangedError("project state changed"))
-				@HttpController.getProjectDocs(@req, @res, @next)
+				@ProjectManager.getProjectDocsAndFlushIfOld = sinon.stub().callsArgWith(3, new Errors.ProjectStateChangedError("project state changed"))
+				@HttpController.getProjectDocsAndFlushIfOld(@req, @res, @next)
 
 			it "should return an HTTP 409 Conflict response", ->
 				@res.send
@@ -485,8 +485,8 @@ describe "HttpController", ->
 
 		describe "when an error occurs", ->
 			beforeEach ->
-				@ProjectManager.getProjectDocs = sinon.stub().callsArgWith(3, new Error("oops"))
-				@HttpController.getProjectDocs(@req, @res, @next)
+				@ProjectManager.getProjectDocsAndFlushIfOld = sinon.stub().callsArgWith(3, new Error("oops"))
+				@HttpController.getProjectDocsAndFlushIfOld(@req, @res, @next)
 
 			it "should call next with the error", ->
 				@next

+ 5 - 5
services/document-updater/test/unit/coffee/ProjectManager/getProjectDocsTests.coffee

@@ -5,7 +5,7 @@ modulePath = "../../../../app/js/ProjectManager.js"
 SandboxedModule = require('sandboxed-module')
 Errors = require "../../../../app/js/Errors.js"
 
-describe "ProjectManager - getProjectDocs", ->
+describe "ProjectManager - getProjectDocsAndFlushIfOld", ->
 	beforeEach ->
 		@ProjectManager = SandboxedModule.require modulePath, requires:
 			"./RedisManager": @RedisManager = {}
@@ -36,7 +36,7 @@ describe "ProjectManager - getProjectDocs", ->
 				.callsArgWith(2, null, @doc_lines[1], @doc_versions[1])
 			@DocumentManager.getDocAndFlushIfOldWithLock.withArgs(@project_id, @doc_ids[2])
 				.callsArgWith(2, null, @doc_lines[2], @doc_versions[2])
-			@ProjectManager.getProjectDocs @project_id, @projectStateHash, @excludeVersions,  (error, docs) =>
+			@ProjectManager.getProjectDocsAndFlushIfOld @project_id, @projectStateHash, @excludeVersions,  (error, docs) =>
 				@callback(error, docs)
 				done()
 
@@ -60,7 +60,7 @@ describe "ProjectManager - getProjectDocs", ->
 		beforeEach (done) ->
 			@doc_ids = ["doc-id-1", "doc-id-2", "doc-id-3"]
 			@RedisManager.checkOrSetProjectState = sinon.stub().callsArgWith(2, null, true)
-			@ProjectManager.getProjectDocs @project_id, @projectStateHash, @excludeVersions,  (error, docs) =>
+			@ProjectManager.getProjectDocsAndFlushIfOld @project_id, @projectStateHash, @excludeVersions,  (error, docs) =>
 				@callback(error, docs)
 				done()
 
@@ -85,13 +85,13 @@ describe "ProjectManager - getProjectDocs", ->
 				.callsArgWith(2, null, ["test doc content"], @doc_versions[1])
 			@DocumentManager.getDocAndFlushIfOldWithLock.withArgs(@project_id, "doc-id-2")
 				.callsArgWith(2, @error = new Error("oops")) # trigger an error
-			@ProjectManager.getProjectDocs @project_id, @projectStateHash, @excludeVersions, (error, docs) =>
+			@ProjectManager.getProjectDocsAndFlushIfOld @project_id, @projectStateHash, @excludeVersions, (error, docs) =>
 				@callback(error)
 				done()
 
 		it "should record the error", ->
 			@logger.error
-				.calledWith(err: @error, project_id: @project_id, doc_id: "doc-id-2", "error getting project doc lines in getProjectDocs")
+				.calledWith(err: @error, project_id: @project_id, doc_id: "doc-id-2", "error getting project doc lines in getProjectDocsAndFlushIfOld")
 				.should.equal true
 
 		it "should call the callback with an error", ->