split request to mongo into separate method

This commit is contained in:
Brian Gough 2017-07-28 15:17:10 +01:00
parent 3e28eca26f
commit d66382382f

View file

@ -110,50 +110,56 @@ module.exports = ClsiManager =
if project.compiler not in ClsiManager.VALID_COMPILERS if project.compiler not in ClsiManager.VALID_COMPILERS
project.compiler = "pdflatex" project.compiler = "pdflatex"
DocumentUpdaterHandler.flushProjectToMongo project_id, (error) -> ClsiManager._getContentFromMongo project_id, (error, docs, files) ->
return callback(error) if error? return callback(error) if error?
ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) -> ClsiManager._finaliseRequest project_id, options, project, docs, files, callback
return callback(error) if error?
ProjectEntityHandler.getAllFiles project_id, (error, files = {}) ->
return callback(error) if error?
resources = [] _getContentFromMongo: (project_id, callback = (error, docs, files) ->) ->
rootResourcePath = null DocumentUpdaterHandler.flushProjectToMongo project_id, (error) ->
rootResourcePathOverride = null 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 _finaliseRequest: (project_id, options, project, docs, files, callback = (error, params) -> ) ->
path = path.replace(/^\//, "") # Remove leading / resources = []
resources.push rootResourcePath = null
path: path rootResourcePathOverride = null
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
rootResourcePath = rootResourcePathOverride if rootResourcePathOverride? for path, doc of docs
if !rootResourcePath? path = path.replace(/^\//, "") # Remove leading /
logger.warn {project_id}, "no root document found, setting to main.tex" resources.push
rootResourcePath = "main.tex" 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 rootResourcePath = rootResourcePathOverride if rootResourcePathOverride?
path = path.replace(/^\//, "") # Remove leading / if !rootResourcePath?
resources.push logger.warn {project_id}, "no root document found, setting to main.tex"
path: path rootResourcePath = "main.tex"
url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}"
modified: file.created?.getTime()
callback null, { for path, file of files
compile: path = path.replace(/^\//, "") # Remove leading /
options: resources.push
compiler: project.compiler path: path
timeout: options.timeout url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}"
imageName: project.imageName modified: file.created?.getTime()
draft: !!options.draft
check: options.check callback null, {
rootResourcePath: rootResourcePath compile:
resources: resources 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) ->) -> wordCount: (project_id, user_id, file, options, callback = (error, response) ->) ->
ClsiManager._buildRequest project_id, options, (error, req) -> ClsiManager._buildRequest project_id, options, (error, req) ->