Revert "Revert "Revert "use ProjectRootDocManager in ClsiManager"""

This reverts commit 14c94880804a3567e2b91e314a707a47bb74be2c.

GitOrigin-RevId: 9039335d01e90cf240f627a7c35889c9ab994a63
This commit is contained in:
Ersun Warncke 2020-02-11 09:19:47 -04:00 committed by Copybot
parent b57ee58883
commit b1c904f824
2 changed files with 90 additions and 79 deletions

View file

@ -466,6 +466,26 @@ const ClsiManager = {
return outputFiles
},
_ensureRootDocumentIsValid(project, callback) {
// if root doc is set and id is contained somewhere in directory tree then accept it
try {
if (
project.rootDoc_id &&
project.rootFolder &&
JSON.stringify(project.rootFolder).includes(project.rootDoc_id)
) {
return callback()
}
} catch (err) {
// continue on errors, which are very unlikely, and just attempt to set the root doc again
logger.error(
{ err, project_id: project._id, rootDoc_id: project.rootDoc_id },
'error validating rootDoc_id'
)
}
ProjectRootDocManager.setRootDocAutomatically(project._id, callback)
},
_buildRequest(projectId, options, callback) {
if (options == null) {
options = {}
@ -496,9 +516,7 @@ const ClsiManager = {
project.compiler = 'pdflatex'
}
ProjectRootDocManager.ensureRootDocumentIsValidForProject(
project,
err => {
ClsiManager._ensureRootDocumentIsValid(project, err => {
if (err != null) {
return callback(
new OError({
@ -507,10 +525,7 @@ const ClsiManager = {
}).withCause(err)
)
}
if (
options.incrementalCompilesEnabled ||
options.syncType != null
) {
if (options.incrementalCompilesEnabled || options.syncType != null) {
// new way, either incremental or full
const timer = new Metrics.Timer('editor.compile-getdocs-redis')
ClsiManager.getContentFromDocUpdaterIfMatch(
@ -558,9 +573,7 @@ const ClsiManager = {
} else {
// old way, always from mongo
const timer = new Metrics.Timer('editor.compile-getdocs-mongo')
ClsiManager._getContentFromMongo(
projectId,
(err, docs, files) => {
ClsiManager._getContentFromMongo(projectId, (err, docs, files) => {
timer.done()
if (err != null) {
return callback(
@ -578,11 +591,9 @@ const ClsiManager = {
files,
callback
)
})
}
)
}
}
)
})
}
)
},

View file

@ -25,7 +25,7 @@ describe('ClsiManager', function() {
getProjectDocsIfMatch: sinon.stub().callsArgWith(2, null, null)
}
this.ProjectRootDocManager = {
ensureRootDocumentIsValidForProject: sinon.stub().yields()
setRootDocAutomatically: sinon.stub().yields()
}
this.logger = {
log: sinon.stub(),