Ver código fonte

Rename flush param to skip_flush in delete doc

Also move it to the query string instead of the body.
Eric Mc Sween 6 anos atrás
pai
commit
9b70eb75b3

+ 16 - 11
services/document-updater/app/coffee/HttpController.coffee

@@ -106,22 +106,27 @@ module.exports = HttpController =
 	deleteDoc: (req, res, next = (error) ->) ->
 	deleteDoc: (req, res, next = (error) ->) ->
 		doc_id = req.params.doc_id
 		doc_id = req.params.doc_id
 		project_id = req.params.project_id
 		project_id = req.params.project_id
-		flush = req.body.flush ? true
-		logger.log project_id: project_id, doc_id: doc_id, flush: flush, "deleting doc via http"
+		skip_flush = req.query.skip_flush == 'true'
 		timer = new Metrics.Timer("http.deleteDoc")
 		timer = new Metrics.Timer("http.deleteDoc")
-		if flush
-			DocumentManager.flushAndDeleteDocWithLock project_id, doc_id, (error) ->
-				timer.done()
-				# There is no harm in flushing project history if the previous call
-				# failed and sometimes it is required
-				HistoryManager.flushProjectChangesAsync project_id
+		if skip_flush
+			logger.log project_id: project_id, doc_id: doc_id, "deleting doc skipping flush via http (contents may be lost)"
 
 
+			# Warning: This action is destructive. Skipping the flush will lose
+			# contents that have not been flushed yet. Use this to fix a document in a
+			# bad state that can't be flushed anyway.
+			DocumentManager.deleteDocWithLock project_id, doc_id, (error) ->
+				timer.done()
 				return next(error) if error?
 				return next(error) if error?
 				logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
 				logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
 				res.send 204 # No Content
 				res.send 204 # No Content
 		else
 		else
-			DocumentManager.deleteDocWithLock project_id, doc_id, (error) ->
+			logger.log project_id: project_id, doc_id: doc_id, "deleting doc via http"
+			DocumentManager.flushAndDeleteDocWithLock project_id, doc_id, (error) ->
 				timer.done()
 				timer.done()
+				# There is no harm in flushing project history if the previous call
+				# failed and sometimes it is required
+				HistoryManager.flushProjectChangesAsync project_id
+
 				return next(error) if error?
 				return next(error) if error?
 				logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
 				logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
 				res.send 204 # No Content
 				res.send 204 # No Content
@@ -212,7 +217,7 @@ module.exports = HttpController =
 
 
 	flushAllProjects: (req, res, next = (error)-> )->
 	flushAllProjects: (req, res, next = (error)-> )->
 		res.setTimeout(5 * 60 * 1000)
 		res.setTimeout(5 * 60 * 1000)
-		options = 
+		options =
 			limit : req.query.limit || 1000
 			limit : req.query.limit || 1000
 			concurrency : req.query.concurrency || 5
 			concurrency : req.query.concurrency || 5
 			dryRun : req.query.dryRun || false
 			dryRun : req.query.dryRun || false
@@ -225,7 +230,7 @@ module.exports = HttpController =
 
 
 	flushQueuedProjects: (req, res, next = (error) ->) ->
 	flushQueuedProjects: (req, res, next = (error) ->) ->
 		res.setTimeout(10 * 60 * 1000)
 		res.setTimeout(10 * 60 * 1000)
-		options = 
+		options =
 			limit : req.query.limit || 1000
 			limit : req.query.limit || 1000
 			timeout: 5 * 60 * 1000
 			timeout: 5 * 60 * 1000
 			min_delete_age: req.query.min_delete_age || 5 * 60 * 1000
 			min_delete_age: req.query.min_delete_age || 5 * 60 * 1000

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

@@ -271,7 +271,7 @@ describe "HttpController", ->
 				params:
 				params:
 					project_id: @project_id
 					project_id: @project_id
 					doc_id: @doc_id
 					doc_id: @doc_id
-				body: {}
+				query: {}
 
 
 		describe "successfully", ->
 		describe "successfully", ->
 			beforeEach ->
 			beforeEach ->
@@ -295,7 +295,7 @@ describe "HttpController", ->
 
 
 			it "should log the request", ->
 			it "should log the request", ->
 				@logger.log
 				@logger.log
-					.calledWith(doc_id: @doc_id, project_id: @project_id, flush: true, "deleting doc via http")
+					.calledWith(doc_id: @doc_id, project_id: @project_id, "deleting doc via http")
 					.should.equal true
 					.should.equal true
 
 
 			it "should time the request", ->
 			it "should time the request", ->
@@ -303,7 +303,7 @@ describe "HttpController", ->
 
 
 		describe "without flush", ->
 		describe "without flush", ->
 			beforeEach ->
 			beforeEach ->
-				@req.body.flush = false
+				@req.query.skip_flush = 'true'
 				@DocumentManager.deleteDocWithLock = sinon.stub().yields()
 				@DocumentManager.deleteDocWithLock = sinon.stub().yields()
 				@HttpController.deleteDoc(@req, @res, @next)
 				@HttpController.deleteDoc(@req, @res, @next)