Sfoglia il codice sorgente

split request to mongo into separate method

Brian Gough 9 anni fa
parent
commit
d66382382f
1 ha cambiato i file con 49 aggiunte e 43 eliminazioni
  1. 49 43
      services/web/app/coffee/Features/Compile/ClsiManager.coffee

+ 49 - 43
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?
-
-						resources = []
-						rootResourcePath = null
-						rootResourcePathOverride = null
-
-						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
-
-						rootResourcePath = rootResourcePathOverride if rootResourcePathOverride?
-						if !rootResourcePath?
-							logger.warn {project_id}, "no root document found, setting to main.tex"
-							rootResourcePath = "main.tex"
-
-						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
-						}
+				ClsiManager._finaliseRequest project_id, options, project, docs, files, callback
+
+	_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)
+
+	_finaliseRequest: (project_id, options, project, docs, files, callback = (error, params) -> ) ->
+		resources = []
+		rootResourcePath = null
+		rootResourcePathOverride = null
+
+		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
+
+		rootResourcePath = rootResourcePathOverride if rootResourcePathOverride?
+		if !rootResourcePath?
+			logger.warn {project_id}, "no root document found, setting to main.tex"
+			rootResourcePath = "main.tex"
+
+		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) ->