add ability to resync project structure

This commit is contained in:
Hayden Faulds 2018-02-28 17:31:43 +00:00
parent b1b2dbcf53
commit 52d6b710bd
4 changed files with 30 additions and 1 deletions

View file

@ -47,7 +47,8 @@ app.post '/project/:project_id/doc/:doc_id', HttpCont
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', HttpController.updateProject
app.post '/project/:project_id', HttpController.updateProject
app.post '/project/:project_id/resync', HttpController.resyncProject
app.post '/project/:project_id/flush', HttpController.flushProject
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

View file

@ -2,6 +2,7 @@ Settings = require "settings-sharelatex"
request = require "request"
logger = require "logger-sharelatex"
HistoryRedisManager = require "./HistoryRedisManager"
RedisManager = require "./RedisManager"
module.exports = HistoryManager =
flushDocChangesAsync: (project_id, doc_id) ->
@ -61,3 +62,14 @@ module.exports = HistoryManager =
prevBlock = Math.floor(previousLength / threshold)
newBlock = Math.floor(length / threshold)
return newBlock != prevBlock
resyncProject: (project_id, docs, files, callback) ->
RedisManager.resyncProjectStructure project_id, docs, files, (error) ->
return callback(error) if error?
callback null
#jobs = _.union
#_.map docs, (doc) -> RedisManager.resyncDoc project_id, doc
#_.map files, (files) -> RedisManager.resyncFile project_id, file
#async.series jobs, callback

View file

@ -169,3 +169,11 @@ module.exports = HttpController =
return next(error) if error?
logger.log project_id: project_id, "updated project via http"
res.send 204 # No Content
resyncProject: (req, res, next = (error) ->) ->
project_id = req.params.project_id
{docs, files} = req.body
HistoryManager.resyncProject project_id, docs, files, (error) ->
return next(error) if error?
res.send 204

View file

@ -321,6 +321,14 @@ module.exports = RedisManager =
getDocIdsInProject: (project_id, callback = (error, doc_ids) ->) ->
rclient.smembers keys.docsInProject(project_id: project_id), callback
resyncProjectStructure: (project_id, docs, files, callback) ->
update =
projectStructure: { docs, files }
meta:
ts: new Date()
jsonUpdate = JSON.stringify update
rclient.rpush projectHistoryKeys.projectHistoryOps({project_id}), jsonUpdate, callback
_serializeRanges: (ranges, callback = (error, serializedRanges) ->) ->
jsonRanges = JSON.stringify(ranges)
if jsonRanges? and jsonRanges.length > MAX_RANGES_SIZE