mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
Revert "Revert "optimize rootDoc_id validation""
This reverts commit 13e4b22daa99b096cf2a9625212a855be59b1fdc. GitOrigin-RevId: f015bc2bb54e98d1271bc2417647638aa80ba843
This commit is contained in:
parent
1c77077e71
commit
f326d632ab
3 changed files with 102 additions and 64 deletions
|
@ -3,6 +3,7 @@ const Settings = require('settings-sharelatex')
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
const ProjectGetter = require('../Project/ProjectGetter')
|
const ProjectGetter = require('../Project/ProjectGetter')
|
||||||
const ProjectEntityHandler = require('../Project/ProjectEntityHandler')
|
const ProjectEntityHandler = require('../Project/ProjectEntityHandler')
|
||||||
|
const ProjectRootDocManager = require('../Project/ProjectRootDocManager')
|
||||||
const logger = require('logger-sharelatex')
|
const logger = require('logger-sharelatex')
|
||||||
const Url = require('url')
|
const Url = require('url')
|
||||||
const OError = require('@overleaf/o-error')
|
const OError = require('@overleaf/o-error')
|
||||||
|
@ -465,15 +466,35 @@ 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) {
|
||||||
|
// ignore errors here, which are very unlikely, and just attempt to set the root doc again
|
||||||
|
}
|
||||||
|
ProjectRootDocManager.setRootDocAutomatically(project._id, callback)
|
||||||
|
},
|
||||||
|
|
||||||
_buildRequest(projectId, options, callback) {
|
_buildRequest(projectId, options, callback) {
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
options = {}
|
options = {}
|
||||||
}
|
}
|
||||||
ProjectGetter.getProject(
|
ProjectGetter.getProject(
|
||||||
projectId,
|
projectId,
|
||||||
{ compiler: 1, rootDoc_id: 1, imageName: 1, rootFolder: 1, rootDoc_id: 1 },
|
{
|
||||||
|
compiler: 1,
|
||||||
|
rootDoc_id: 1,
|
||||||
|
imageName: 1,
|
||||||
|
rootFolder: 1
|
||||||
|
},
|
||||||
(err, project) => {
|
(err, project) => {
|
||||||
console.log("GGGG", project)
|
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
return callback(
|
return callback(
|
||||||
new OError({
|
new OError({
|
||||||
|
@ -491,71 +512,84 @@ const ClsiManager = {
|
||||||
project.compiler = 'pdflatex'
|
project.compiler = 'pdflatex'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.incrementalCompilesEnabled || options.syncType != null) {
|
ClsiManager._ensureRootDocumentIsValid(project, err => {
|
||||||
// new way, either incremental or full
|
if (err != null) {
|
||||||
const timer = new Metrics.Timer('editor.compile-getdocs-redis')
|
return callback(
|
||||||
ClsiManager.getContentFromDocUpdaterIfMatch(
|
new OError({
|
||||||
projectId,
|
message: 'error setting rootDoc_id',
|
||||||
project,
|
info: { projectId }
|
||||||
options,
|
}).withCause(err)
|
||||||
(err, projectStateHash, docUpdaterDocs) => {
|
)
|
||||||
|
}
|
||||||
|
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()
|
timer.done()
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
logger.error({ err, projectId }, 'error checking project state')
|
return callback(
|
||||||
// note: we don't bail out when there's an error getting
|
new OError({
|
||||||
// incremental files from the docupdater, we just fall back
|
message: 'failed to get contents from Mongo',
|
||||||
// to a normal compile below
|
info: { projectId }
|
||||||
}
|
}).withCause(err)
|
||||||
// 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
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
ClsiManager._finaliseRequest(
|
||||||
)
|
projectId,
|
||||||
} else {
|
options,
|
||||||
// old way, always from mongo
|
project,
|
||||||
const timer = new Metrics.Timer('editor.compile-getdocs-mongo')
|
docs,
|
||||||
ClsiManager._getContentFromMongo(projectId, (err, docs, files) => {
|
files,
|
||||||
timer.done()
|
callback
|
||||||
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
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,6 +24,9 @@ describe('ClsiManager', function() {
|
||||||
this.DocumentUpdaterHandler = {
|
this.DocumentUpdaterHandler = {
|
||||||
getProjectDocsIfMatch: sinon.stub().callsArgWith(2, null, null)
|
getProjectDocsIfMatch: sinon.stub().callsArgWith(2, null, null)
|
||||||
}
|
}
|
||||||
|
this.ProjectRootDocManager = {
|
||||||
|
setRootDocAutomatically: sinon.stub().yields()
|
||||||
|
}
|
||||||
this.logger = {
|
this.logger = {
|
||||||
log: sinon.stub(),
|
log: sinon.stub(),
|
||||||
error: sinon.stub(),
|
error: sinon.stub(),
|
||||||
|
@ -63,6 +66,7 @@ describe('ClsiManager', function() {
|
||||||
},
|
},
|
||||||
'../Project/ProjectEntityHandler': this.ProjectEntityHandler,
|
'../Project/ProjectEntityHandler': this.ProjectEntityHandler,
|
||||||
'../Project/ProjectGetter': this.ProjectGetter,
|
'../Project/ProjectGetter': this.ProjectGetter,
|
||||||
|
'../Project/ProjectRootDocManager': this.ProjectRootDocManager,
|
||||||
'../DocumentUpdater/DocumentUpdaterHandler': this
|
'../DocumentUpdater/DocumentUpdaterHandler': this
|
||||||
.DocumentUpdaterHandler,
|
.DocumentUpdaterHandler,
|
||||||
'./ClsiCookieManager': () => this.ClsiCookieManager,
|
'./ClsiCookieManager': () => this.ClsiCookieManager,
|
||||||
|
|
|
@ -76,7 +76,7 @@ describe('CompileManager', function() {
|
||||||
this.CompileManager._checkIfRecentlyCompiled = sinon
|
this.CompileManager._checkIfRecentlyCompiled = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(2, null, false)
|
.callsArgWith(2, null, false)
|
||||||
this.ProjectRootDocManager.ensureRootDocumentIsValid = sinon
|
this.ProjectRootDocManager.ensureRootDocumentIsSet = sinon
|
||||||
.stub()
|
.stub()
|
||||||
.callsArgWith(1, null)
|
.callsArgWith(1, null)
|
||||||
this.CompileManager.getProjectCompileLimits = sinon
|
this.CompileManager.getProjectCompileLimits = sinon
|
||||||
|
@ -115,7 +115,7 @@ describe('CompileManager', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should ensure that the root document is set', function() {
|
it('should ensure that the root document is set', function() {
|
||||||
return this.ProjectRootDocManager.ensureRootDocumentIsValid
|
return this.ProjectRootDocManager.ensureRootDocumentIsSet
|
||||||
.calledWith(this.project_id)
|
.calledWith(this.project_id)
|
||||||
.should.equal(true)
|
.should.equal(true)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue