Revert "Revert "use ProjectRootDocManager in ClsiManager""

This reverts commit 98c0b9246eb29a9d0bdab14a04d456473a1b4a14.

GitOrigin-RevId: 14c94880804a3567e2b91e314a707a47bb74be2c
This commit is contained in:
Ersun Warncke 2020-02-05 08:53:31 -04:00 committed by Copybot
parent 725a3c5282
commit 22fcbe8648
2 changed files with 86 additions and 97 deletions

View file

@ -466,26 +466,6 @@ const ClsiManager = {
return outputFiles 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) { _buildRequest(projectId, options, callback) {
if (options == null) { if (options == null) {
options = {} options = {}
@ -516,84 +496,93 @@ const ClsiManager = {
project.compiler = 'pdflatex' project.compiler = 'pdflatex'
} }
ClsiManager._ensureRootDocumentIsValid(project, err => { ProjectRootDocManager.ensureRootDocumentIsValidForProject(
if (err != null) { project,
return callback( err => {
new OError({ if (err != null) {
message: 'error setting rootDoc_id', return callback(
info: { projectId } new OError({
}).withCause(err) message: 'error setting rootDoc_id',
) info: { projectId }
} }).withCause(err)
if (options.incrementalCompilesEnabled || options.syncType != null) {
// new way, either incremental or full
const timer = new Metrics.Timer('editor.compile-getdocs-redis')
ClsiManager.getContentFromDocUpdaterIfMatch(
projectId,
project,
options,
(err, projectStateHash, docUpdaterDocs) => {
timer.done()
if (err != null) {
logger.error(
{ err, projectId },
'error checking project state'
)
// note: we don't bail out when there's an error getting
// incremental files from the docupdater, we just fall back
// to a normal compile below
}
// see if we can send an incremental update to the CLSI
if (
docUpdaterDocs != null &&
options.syncType !== 'full' &&
err == null
) {
Metrics.inc('compile-from-redis')
ClsiManager._buildRequestFromDocupdater(
projectId,
options,
project,
projectStateHash,
docUpdaterDocs,
callback
)
} else {
Metrics.inc('compile-from-mongo')
ClsiManager._buildRequestFromMongo(
projectId,
options,
project,
projectStateHash,
callback
)
}
}
)
} else {
// old way, always from mongo
const timer = new Metrics.Timer('editor.compile-getdocs-mongo')
ClsiManager._getContentFromMongo(projectId, (err, docs, files) => {
timer.done()
if (err != null) {
return callback(
new OError({
message: 'failed to get contents from Mongo',
info: { projectId }
}).withCause(err)
)
}
ClsiManager._finaliseRequest(
projectId,
options,
project,
docs,
files,
callback
) )
}) }
if (
options.incrementalCompilesEnabled ||
options.syncType != null
) {
// new way, either incremental or full
const timer = new Metrics.Timer('editor.compile-getdocs-redis')
ClsiManager.getContentFromDocUpdaterIfMatch(
projectId,
project,
options,
(err, projectStateHash, docUpdaterDocs) => {
timer.done()
if (err != null) {
logger.error(
{ err, projectId },
'error checking project state'
)
// note: we don't bail out when there's an error getting
// incremental files from the docupdater, we just fall back
// to a normal compile below
}
// see if we can send an incremental update to the CLSI
if (
docUpdaterDocs != null &&
options.syncType !== 'full' &&
err == null
) {
Metrics.inc('compile-from-redis')
ClsiManager._buildRequestFromDocupdater(
projectId,
options,
project,
projectStateHash,
docUpdaterDocs,
callback
)
} else {
Metrics.inc('compile-from-mongo')
ClsiManager._buildRequestFromMongo(
projectId,
options,
project,
projectStateHash,
callback
)
}
}
)
} else {
// old way, always from mongo
const timer = new Metrics.Timer('editor.compile-getdocs-mongo')
ClsiManager._getContentFromMongo(
projectId,
(err, docs, files) => {
timer.done()
if (err != null) {
return callback(
new OError({
message: 'failed to get contents from Mongo',
info: { projectId }
}).withCause(err)
)
}
ClsiManager._finaliseRequest(
projectId,
options,
project,
docs,
files,
callback
)
}
)
}
} }
}) )
} }
) )
}, },

View file

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