diff --git a/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee b/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee index e3cbf4ce8e..3d8ae48478 100644 --- a/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee +++ b/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee @@ -205,32 +205,17 @@ module.exports = DocumentUpdaterHandler = logger.error {project_id, doc_id, thread_id}, "doc updater returned a non-success status code: #{res.statusCode}" callback new Error("doc updater returned a non-success status code: #{res.statusCode}") - resyncProject: (project_id, callback) -> - ProjectEntityHandler = require "../Project/ProjectEntityHandler" - ProjectGetter.getProject project_id, rootFolder: true, (error, project) -> - return callback(error) if error? - ProjectEntityHandler.getAllEntitiesFromProject project, (error, docs, files) -> - return callback(error) if error? - - docs = _.map docs, (doc) -> - doc: doc.doc._id - path: doc.path - - files = _.map files, (file) -> - file: file.file._id - path: file.path - url: FileStoreHandler._buildUrl(project_id, file.file._id) - - request.post - url: "#{settings.apis.documentupdater.url}/project/#{project_id}/resync" - json: { docs, files } - , (error, res, body) -> - if error? - logger.error {error, project_id}, "error resyncing project in doc updater" - callback(error) - else if res.statusCode >= 200 and res.statusCode < 300 - logger.log {project_id}, "resynced project in doc updater" - callback() + resyncProject: (project_id, docs, files, callback) -> + request.post + url: "#{settings.apis.documentupdater.url}/project/#{project_id}/resync" + json: { docs, files } + , (error, res, body) -> + if error? + logger.error {error, project_id}, "error resyncing project in doc updater" + callback(error) + else if res.statusCode >= 200 and res.statusCode < 300 + logger.log {project_id}, "resynced project in doc updater" + callback() updateProjectStructure : (project_id, userId, changes, callback = (error) ->)-> return callback() if !settings.apis.project_history?.sendProjectStructureOps diff --git a/services/web/app/coffee/Features/History/HistoryController.coffee b/services/web/app/coffee/Features/History/HistoryController.coffee index 5ce0338306..aa0a1f5101 100644 --- a/services/web/app/coffee/Features/History/HistoryController.coffee +++ b/services/web/app/coffee/Features/History/HistoryController.coffee @@ -2,8 +2,8 @@ logger = require "logger-sharelatex" request = require "request" settings = require "settings-sharelatex" AuthenticationController = require "../Authentication/AuthenticationController" -DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler" ProjectDetailsHandler = require "../Project/ProjectDetailsHandler" +ProjectEntityUpdateHandler = require "../Project/ProjectEntityUpdateHandler" HistoryManager = require "./HistoryManager" module.exports = HistoryController = @@ -66,6 +66,6 @@ module.exports = HistoryController = resyncProject: (req, res, next = (error) ->) -> project_id = req.params.Project_id - DocumentUpdaterHandler.resyncProject project_id, (error) -> + ProjectEntityUpdateHandler.resyncProject project_id, (error) -> return next(error) if error? res.sendStatus 204 diff --git a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee index aadc0ac0f8..af41c3269c 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee @@ -313,6 +313,25 @@ module.exports = ProjectEntityUpdateHandler = self = TpdsUpdateSender.moveEntity({project_id, startPath, endPath, project_name, rev}) DocumentUpdaterHandler.updateProjectStructure project_id, userId, changes, callback + # This doesn't directly update project structure but we need to take the lock + # to prevent anything else being queued before the resync update + resyncProject: wrapWithLock (project_id, callback) -> + ProjectGetter.getProject project_id, rootFolder: true, (error, project) -> + return callback(error) if error? + ProjectEntityHandler.getAllEntitiesFromProject project, (error, docs, files) -> + return callback(error) if error? + + docs = _.map docs, (doc) -> + doc: doc.doc._id + path: doc.path + + files = _.map files, (file) -> + file: file.file._id + path: file.path + url: FileStoreHandler._buildUrl(project_id, file.file._id) + + DocumentUpdaterHandler.resyncProject project_id, docs, files, callback + _cleanUpEntity: (project, entity, entityType, path, userId, callback = (error) ->) -> if(entityType.indexOf("file") != -1) self._cleanUpFile project, entity, path, userId, callback