Add methods to bulk accept changes.

This commit is contained in:
Paulo Reis 2017-05-04 15:32:54 +01:00
parent fe5711ef07
commit d530ee9501
4 changed files with 49 additions and 7 deletions

View file

@ -42,14 +42,15 @@ app.param 'doc_id', (req, res, next, doc_id) ->
else
next new Error("invalid doc id")
app.get '/project/:project_id/doc/:doc_id', HttpController.getDoc
app.post '/project/:project_id/doc/:doc_id', HttpController.setDoc
app.post '/project/:project_id/doc/:doc_id/flush', HttpController.flushDocIfLoaded
app.delete '/project/:project_id/doc/:doc_id', HttpController.flushAndDeleteDoc
app.delete '/project/:project_id', HttpController.deleteProject
app.post '/project/:project_id/flush', HttpController.flushProject
app.get '/project/:project_id/doc/:doc_id', HttpController.getDoc
app.post '/project/:project_id/doc/:doc_id', HttpController.setDoc
app.post '/project/:project_id/doc/:doc_id/flush', HttpController.flushDocIfLoaded
app.delete '/project/:project_id/doc/:doc_id', HttpController.flushAndDeleteDoc
app.delete '/project/:project_id', HttpController.deleteProject
app.post '/project/:project_id/flush', HttpController.flushProject
app.post '/project/:project_id/doc/:doc_id/change/:change_id/accept', HttpController.acceptChange
app.del '/project/:project_id/doc/:doc_id/comment/:comment_id', HttpController.deleteComment
app.post '/project/:project_id/doc/:doc_id/change/accept', HttpController.bulkAcceptChanges
app.del '/project/:project_id/doc/:doc_id/comment/:comment_id', HttpController.deleteComment
app.get '/total', (req, res)->
timer = new Metrics.Timer("http.allDocList")

View file

@ -139,6 +139,22 @@ module.exports = DocumentManager =
RedisManager.updateDocument doc_id, lines, version, [], new_ranges, (error) ->
return callback(error) if error?
callback()
bulkAcceptChanges: (project_id, doc_id, change_ids, _callback = (error) ->) ->
timer = new Metrics.Timer("docManager.bulkAcceptChanges")
callback = (args...) ->
timer.done()
_callback(args...)
DocumentManager.getDoc project_id, doc_id, (error, lines, version, ranges) ->
return callback(error) if error?
if !lines? or !version?
return callback(new Errors.NotFoundError("document not found: #{doc_id}"))
RangesManager.bulkAcceptChanges change_ids, ranges, (error, new_ranges) ->
return callback(error) if error?
RedisManager.updateDocument doc_id, lines, version, [], new_ranges, (error) ->
return callback(error) if error?
callback()
deleteComment: (project_id, doc_id, comment_id, _callback = (error) ->) ->
timer = new Metrics.Timer("docManager.deleteComment")
@ -180,6 +196,10 @@ module.exports = DocumentManager =
UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.acceptChange, project_id, doc_id, change_id, callback
bulkAcceptChangesWithLock: (project_id, doc_id, change_ids, callback = (error) ->) ->
UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.bulkAcceptChanges, project_id, doc_id, change_ids, callback
deleteCommentWithLock: (project_id, doc_id, thread_id, callback = (error) ->) ->
UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.deleteComment, project_id, doc_id, thread_id, callback

View file

@ -105,6 +105,18 @@ module.exports = HttpController =
return next(error) if error?
logger.log {project_id, doc_id, change_id}, "accepted change via http"
res.send 204 # No Content
bulkAcceptChanges: (req, res, next = (error) ->) ->
{project_id, doc_id} = req.params
{change_ids} = req.body
change_ids ?= []
logger.log {project_id, doc_id}, "accepting #{ change_ids.length } changes via http"
timer = new Metrics.Timer("http.bulkAcceptChanges")
DocumentManager.bulkAcceptChangesWithLock project_id, doc_id, change_ids, (error) ->
timer.done()
return next(error) if error?
logger.log {project_id, doc_id}, "accepted #{ change_ids.length } changes via http"
res.send 204 # No Content
deleteComment: (req, res, next = (error) ->) ->
{project_id, doc_id, comment_id} = req.params

View file

@ -41,6 +41,15 @@ module.exports = RangesManager =
response = RangesManager._getRanges(rangesTracker)
callback null, response
bulkAcceptChanges: (change_ids, ranges, callback = (error, ranges) ->) ->
{changes, comments} = ranges
logger.log {change_id}, "accepting #{ change_ids.length } changes in ranges"
rangesTracker = new RangesTracker(changes, comments)
for change_id in change_ids
rangesTracker.removeChangeId(change_id)
response = RangesManager._getRanges(rangesTracker)
callback null, response
deleteComment: (comment_id, ranges, callback = (error, ranges) ->) ->
{changes, comments} = ranges
logger.log {comment_id}, "deleting comment in ranges"