mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 03:42:13 +00:00
Merge pull request #38 from sharelatex/bg-flush-project-history-on-delete
ensure that project history is flushed when the project is deleted
This commit is contained in:
commit
78d04adfec
3 changed files with 25 additions and 13 deletions
|
@ -20,16 +20,25 @@ module.exports = HistoryManager =
|
|||
else if res.statusCode < 200 and res.statusCode >= 300
|
||||
logger.error { doc_id, project_id }, "track changes api returned a failure status code: #{res.statusCode}"
|
||||
|
||||
# flush changes in the background
|
||||
flushProjectChangesAsync: (project_id) ->
|
||||
return if !Settings.apis?.project_history?.enabled
|
||||
HistoryManager.flushProjectChanges project_id, ->
|
||||
|
||||
# flush changes and callback (for when we need to know the queue is flushed)
|
||||
flushProjectChanges: (project_id, callback = (error) ->) ->
|
||||
return callback() if !Settings.apis?.project_history?.enabled
|
||||
url = "#{Settings.apis.project_history.url}/project/#{project_id}/flush"
|
||||
logger.log { project_id, url }, "flushing doc in project history api"
|
||||
request.post url, (error, res, body)->
|
||||
if error?
|
||||
logger.error { error, project_id}, "project history doc to track changes api"
|
||||
return callback(error)
|
||||
else if res.statusCode < 200 and res.statusCode >= 300
|
||||
logger.error { project_id }, "project history api returned a failure status code: #{res.statusCode}"
|
||||
return callback(error)
|
||||
else
|
||||
return callback()
|
||||
|
||||
FLUSH_DOC_EVERY_N_OPS: 100
|
||||
FLUSH_PROJECT_EVERY_N_OPS: 500
|
||||
|
|
|
@ -60,14 +60,17 @@ module.exports = ProjectManager =
|
|||
|
||||
logger.log project_id: project_id, doc_ids: doc_ids, "deleting docs"
|
||||
async.series jobs, () ->
|
||||
# There is no harm in flushing project history if the previous call
|
||||
# failed and sometimes it is required
|
||||
HistoryManager.flushProjectChangesAsync project_id
|
||||
|
||||
if errors.length > 0
|
||||
callback new Error("Errors deleting docs. See log for details")
|
||||
else
|
||||
callback(null)
|
||||
# When deleting the project here we want to ensure that project
|
||||
# history is completely flushed because the project may be
|
||||
# deleted in web after this call completes, and so further
|
||||
# attempts to flush would fail after that.
|
||||
HistoryManager.flushProjectChanges project_id, (error) ->
|
||||
if errors.length > 0
|
||||
callback new Error("Errors deleting docs. See log for details")
|
||||
else if error?
|
||||
callback(error)
|
||||
else
|
||||
callback(null)
|
||||
|
||||
getProjectDocsAndFlushIfOld: (project_id, projectStateHash, excludeVersions = {}, _callback = (error, docs) ->) ->
|
||||
timer = new Metrics.Timer("projectManager.getProjectDocsAndFlushIfOld")
|
||||
|
|
|
@ -12,7 +12,7 @@ describe "ProjectManager - flushAndDeleteProject", ->
|
|||
"./DocumentManager": @DocumentManager = {}
|
||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
||||
"./HistoryManager": @HistoryManager =
|
||||
flushProjectChangesAsync: sinon.stub()
|
||||
flushProjectChanges: sinon.stub().callsArg(1)
|
||||
"./Metrics": @Metrics =
|
||||
Timer: class Timer
|
||||
done: sinon.stub()
|
||||
|
@ -40,8 +40,8 @@ describe "ProjectManager - flushAndDeleteProject", ->
|
|||
.should.equal true
|
||||
|
||||
it "should flush project history", ->
|
||||
@HistoryManager.flushProjectChangesAsync
|
||||
.calledWithExactly(@project_id)
|
||||
@HistoryManager.flushProjectChanges
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback without error", ->
|
||||
|
@ -70,8 +70,8 @@ describe "ProjectManager - flushAndDeleteProject", ->
|
|||
.should.equal true
|
||||
|
||||
it "should still flush project history", ->
|
||||
@HistoryManager.flushProjectChangesAsync
|
||||
.calledWithExactly(@project_id)
|
||||
@HistoryManager.flushProjectChanges
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should record the error", ->
|
||||
|
|
Loading…
Reference in a new issue