Rename flush param to skip_flush in delete doc

Also move it to the query string instead of the body.
This commit is contained in:
Eric Mc Sween 2020-03-09 16:27:32 -04:00
parent c09bc0e868
commit 9b70eb75b3
2 changed files with 19 additions and 14 deletions

View file

@ -106,10 +106,21 @@ module.exports = HttpController =
deleteDoc: (req, res, next = (error) ->) ->
doc_id = req.params.doc_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")
if flush
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?
logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
res.send 204 # No Content
else
logger.log project_id: project_id, doc_id: doc_id, "deleting doc via http"
DocumentManager.flushAndDeleteDocWithLock project_id, doc_id, (error) ->
timer.done()
# There is no harm in flushing project history if the previous call
@ -119,12 +130,6 @@ module.exports = HttpController =
return next(error) if error?
logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
res.send 204 # No Content
else
DocumentManager.deleteDocWithLock project_id, doc_id, (error) ->
timer.done()
return next(error) if error?
logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
res.send 204 # No Content
flushProject: (req, res, next = (error) ->) ->
project_id = req.params.project_id
@ -212,7 +217,7 @@ module.exports = HttpController =
flushAllProjects: (req, res, next = (error)-> )->
res.setTimeout(5 * 60 * 1000)
options =
options =
limit : req.query.limit || 1000
concurrency : req.query.concurrency || 5
dryRun : req.query.dryRun || false
@ -225,7 +230,7 @@ module.exports = HttpController =
flushQueuedProjects: (req, res, next = (error) ->) ->
res.setTimeout(10 * 60 * 1000)
options =
options =
limit : req.query.limit || 1000
timeout: 5 * 60 * 1000
min_delete_age: req.query.min_delete_age || 5 * 60 * 1000

View file

@ -271,7 +271,7 @@ describe "HttpController", ->
params:
project_id: @project_id
doc_id: @doc_id
body: {}
query: {}
describe "successfully", ->
beforeEach ->
@ -295,7 +295,7 @@ describe "HttpController", ->
it "should log the request", ->
@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
it "should time the request", ->
@ -303,7 +303,7 @@ describe "HttpController", ->
describe "without flush", ->
beforeEach ->
@req.body.flush = false
@req.query.skip_flush = 'true'
@DocumentManager.deleteDocWithLock = sinon.stub().yields()
@HttpController.deleteDoc(@req, @res, @next)