From d66382382f477a92404246cff0eb1f2020b3f0ab Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 28 Jul 2017 15:17:10 +0100 Subject: [PATCH] split request to mongo into separate method --- .../Features/Compile/ClsiManager.coffee | 82 ++++++++++--------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index 35b49881ac..7caa9cc174 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiManager.coffee @@ -110,50 +110,56 @@ module.exports = ClsiManager = if project.compiler not in ClsiManager.VALID_COMPILERS project.compiler = "pdflatex" - DocumentUpdaterHandler.flushProjectToMongo project_id, (error) -> + ClsiManager._getContentFromMongo project_id, (error, docs, files) -> return callback(error) if error? - ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) -> - return callback(error) if error? - ProjectEntityHandler.getAllFiles project_id, (error, files = {}) -> - return callback(error) if error? + ClsiManager._finaliseRequest project_id, options, project, docs, files, callback - resources = [] - rootResourcePath = null - rootResourcePathOverride = null + _getContentFromMongo: (project_id, callback = (error, docs, files) ->) -> + DocumentUpdaterHandler.flushProjectToMongo project_id, (error) -> + return callback(error) if error? + ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) -> + return callback(error) if error? + ProjectEntityHandler.getAllFiles project_id, (error, files = {}) -> + callback(null, docs, files) - for path, doc of docs - path = path.replace(/^\//, "") # Remove leading / - resources.push - path: path - content: doc.lines.join("\n") - if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString() - rootResourcePath = path - if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString() - rootResourcePathOverride = path + _finaliseRequest: (project_id, options, project, docs, files, callback = (error, params) -> ) -> + resources = [] + rootResourcePath = null + rootResourcePathOverride = null - rootResourcePath = rootResourcePathOverride if rootResourcePathOverride? - if !rootResourcePath? - logger.warn {project_id}, "no root document found, setting to main.tex" - rootResourcePath = "main.tex" + for path, doc of docs + path = path.replace(/^\//, "") # Remove leading / + resources.push + path: path + content: doc.lines.join("\n") + if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString() + rootResourcePath = path + if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString() + rootResourcePathOverride = path - for path, file of files - path = path.replace(/^\//, "") # Remove leading / - resources.push - path: path - url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}" - modified: file.created?.getTime() + rootResourcePath = rootResourcePathOverride if rootResourcePathOverride? + if !rootResourcePath? + logger.warn {project_id}, "no root document found, setting to main.tex" + rootResourcePath = "main.tex" - callback null, { - compile: - options: - compiler: project.compiler - timeout: options.timeout - imageName: project.imageName - draft: !!options.draft - check: options.check - rootResourcePath: rootResourcePath - resources: resources - } + for path, file of files + path = path.replace(/^\//, "") # Remove leading / + resources.push + path: path + url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}" + modified: file.created?.getTime() + + callback null, { + compile: + options: + compiler: project.compiler + timeout: options.timeout + imageName: project.imageName + draft: !!options.draft + check: options.check + rootResourcePath: rootResourcePath + resources: resources + } wordCount: (project_id, user_id, file, options, callback = (error, response) ->) -> ClsiManager._buildRequest project_id, options, (error, req) ->