mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 05:52:57 +00:00
Consolidate methods to accept changes.
This commit is contained in:
parent
d530ee9501
commit
9b8a2c3030
4 changed files with 15 additions and 42 deletions
|
@ -48,8 +48,8 @@ app.post '/project/:project_id/doc/:doc_id/flush', HttpCont
|
|||
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.post '/project/:project_id/doc/:doc_id/change/accept', HttpController.bulkAcceptChanges
|
||||
app.post '/project/:project_id/doc/:doc_id/change/:change_id/accept', HttpController.acceptChanges
|
||||
app.post '/project/:project_id/doc/:doc_id/change/accept', HttpController.acceptChanges
|
||||
app.del '/project/:project_id/doc/:doc_id/comment/:comment_id', HttpController.deleteComment
|
||||
|
||||
app.get '/total', (req, res)->
|
||||
|
|
|
@ -123,9 +123,9 @@ module.exports = DocumentManager =
|
|||
RedisManager.removeDocFromMemory project_id, doc_id, (error) ->
|
||||
return callback(error) if error?
|
||||
callback null
|
||||
|
||||
acceptChange: (project_id, doc_id, change_id, _callback = (error) ->) ->
|
||||
timer = new Metrics.Timer("docManager.acceptChange")
|
||||
|
||||
acceptChanges: (project_id, doc_id, change_ids = [], _callback = (error) ->) ->
|
||||
timer = new Metrics.Timer("docManager.acceptChanges")
|
||||
callback = (args...) ->
|
||||
timer.done()
|
||||
_callback(args...)
|
||||
|
@ -134,23 +134,7 @@ module.exports = DocumentManager =
|
|||
return callback(error) if error?
|
||||
if !lines? or !version?
|
||||
return callback(new Errors.NotFoundError("document not found: #{doc_id}"))
|
||||
RangesManager.acceptChange change_id, ranges, (error, new_ranges) ->
|
||||
return callback(error) if error?
|
||||
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) ->
|
||||
RangesManager.acceptChanges 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?
|
||||
|
@ -192,13 +176,9 @@ module.exports = DocumentManager =
|
|||
UpdateManager = require "./UpdateManager"
|
||||
UpdateManager.lockUpdatesAndDo DocumentManager.flushAndDeleteDoc, project_id, doc_id, callback
|
||||
|
||||
acceptChangeWithLock: (project_id, doc_id, change_id, callback = (error) ->) ->
|
||||
acceptChangesWithLock: (project_id, doc_id, change_ids, callback = (error) ->) ->
|
||||
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
|
||||
UpdateManager.lockUpdatesAndDo DocumentManager.acceptChanges, project_id, doc_id, change_ids, callback
|
||||
|
||||
deleteCommentWithLock: (project_id, doc_id, thread_id, callback = (error) ->) ->
|
||||
UpdateManager = require "./UpdateManager"
|
||||
|
|
|
@ -100,19 +100,20 @@ module.exports = HttpController =
|
|||
{project_id, doc_id, change_id} = req.params
|
||||
logger.log {project_id, doc_id, change_id}, "accepting change via http"
|
||||
timer = new Metrics.Timer("http.acceptChange")
|
||||
DocumentManager.acceptChangeWithLock project_id, doc_id, change_id, (error) ->
|
||||
DocumentManager.acceptChangesWithLock project_id, doc_id, [ change_id ], (error) ->
|
||||
timer.done()
|
||||
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) ->) ->
|
||||
acceptChanges: (req, res, next = (error) ->) ->
|
||||
{project_id, doc_id} = req.params
|
||||
{change_ids} = req.body
|
||||
change_ids ?= []
|
||||
if !change_ids?
|
||||
change_ids = [ req.params.change_id ]
|
||||
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 = new Metrics.Timer("http.acceptChanges")
|
||||
DocumentManager.acceptChangesWithLock 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"
|
||||
|
|
|
@ -33,15 +33,7 @@ module.exports = RangesManager =
|
|||
logger.log {project_id, doc_id, changesCount: response.changes?.length, commentsCount: response.comments?.length}, "applied updates to ranges"
|
||||
callback null, response
|
||||
|
||||
acceptChange: (change_id, ranges, callback = (error, ranges) ->) ->
|
||||
{changes, comments} = ranges
|
||||
logger.log {change_id}, "accepting change in ranges"
|
||||
rangesTracker = new RangesTracker(changes, comments)
|
||||
rangesTracker.removeChangeId(change_id)
|
||||
response = RangesManager._getRanges(rangesTracker)
|
||||
callback null, response
|
||||
|
||||
bulkAcceptChanges: (change_ids, ranges, callback = (error, ranges) ->) ->
|
||||
acceptChanges: (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)
|
||||
|
|
Loading…
Reference in a new issue