|
@@ -178,19 +178,34 @@ module.exports = OutputCacheManager = {
|
|
|
result,
|
|
result,
|
|
|
outputDir,
|
|
outputDir,
|
|
|
stats,
|
|
stats,
|
|
|
- (err, result) => {
|
|
|
|
|
- if (err) return callback(err, result)
|
|
|
|
|
-
|
|
|
|
|
- if (!Settings.enablePdfCaching || !request.enablePdfCaching) {
|
|
|
|
|
- return callback(null, result)
|
|
|
|
|
|
|
+ (err, outputFiles) => {
|
|
|
|
|
+ if (err) return callback(err, outputFiles)
|
|
|
|
|
+
|
|
|
|
|
+ const enablePdfCaching = request.enablePdfCaching
|
|
|
|
|
+ const enablePdfCachingDark =
|
|
|
|
|
+ Settings.enablePdfCachingDark && !request.enablePdfCaching
|
|
|
|
|
+ if (
|
|
|
|
|
+ !Settings.enablePdfCaching ||
|
|
|
|
|
+ (!enablePdfCaching && !enablePdfCachingDark)
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return callback(null, outputFiles)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
OutputCacheManager.saveStreamsInContentDir(
|
|
OutputCacheManager.saveStreamsInContentDir(
|
|
|
- { request, stats, timings },
|
|
|
|
|
- result,
|
|
|
|
|
|
|
+ { request, stats, timings, enablePdfCachingDark },
|
|
|
|
|
+ outputFiles,
|
|
|
compileDir,
|
|
compileDir,
|
|
|
outputDir,
|
|
outputDir,
|
|
|
- callback
|
|
|
|
|
|
|
+ err => {
|
|
|
|
|
+ if (err) {
|
|
|
|
|
+ logger.warn(
|
|
|
|
|
+ { err, outputDir, stats, timings },
|
|
|
|
|
+ 'pdf caching failed'
|
|
|
|
|
+ )
|
|
|
|
|
+ return callback(null, outputFiles)
|
|
|
|
|
+ }
|
|
|
|
|
+ callback(err, outputFiles)
|
|
|
|
|
+ }
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
@@ -348,7 +363,7 @@ module.exports = OutputCacheManager = {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
saveStreamsInContentDir(
|
|
saveStreamsInContentDir(
|
|
|
- { request, stats, timings },
|
|
|
|
|
|
|
+ { request, stats, timings, enablePdfCachingDark },
|
|
|
outputFiles,
|
|
outputFiles,
|
|
|
compileDir,
|
|
compileDir,
|
|
|
outputDir,
|
|
outputDir,
|
|
@@ -357,7 +372,7 @@ module.exports = OutputCacheManager = {
|
|
|
const cacheRoot = Path.join(outputDir, OutputCacheManager.CONTENT_SUBDIR)
|
|
const cacheRoot = Path.join(outputDir, OutputCacheManager.CONTENT_SUBDIR)
|
|
|
// check if content dir exists
|
|
// check if content dir exists
|
|
|
OutputCacheManager.ensureContentDir(cacheRoot, function (err, contentDir) {
|
|
OutputCacheManager.ensureContentDir(cacheRoot, function (err, contentDir) {
|
|
|
- if (err) return callback(err, outputFiles)
|
|
|
|
|
|
|
+ if (err) return callback(err)
|
|
|
|
|
|
|
|
const outputFile = outputFiles.find(x => x.path === 'output.pdf')
|
|
const outputFile = outputFiles.find(x => x.path === 'output.pdf')
|
|
|
if (outputFile) {
|
|
if (outputFile) {
|
|
@@ -381,7 +396,7 @@ module.exports = OutputCacheManager = {
|
|
|
if (err && err instanceof QueueLimitReachedError) {
|
|
if (err && err instanceof QueueLimitReachedError) {
|
|
|
logger.warn({ err, outputDir }, 'pdf caching queue limit reached')
|
|
logger.warn({ err, outputDir }, 'pdf caching queue limit reached')
|
|
|
stats['pdf-caching-queue-limit-reached'] = 1
|
|
stats['pdf-caching-queue-limit-reached'] = 1
|
|
|
- return callback(null, outputFiles)
|
|
|
|
|
|
|
+ return callback(null)
|
|
|
}
|
|
}
|
|
|
if (err && err instanceof TimedOutError) {
|
|
if (err && err instanceof TimedOutError) {
|
|
|
logger.warn(
|
|
logger.warn(
|
|
@@ -389,9 +404,9 @@ module.exports = OutputCacheManager = {
|
|
|
'pdf caching timed out'
|
|
'pdf caching timed out'
|
|
|
)
|
|
)
|
|
|
stats['pdf-caching-timed-out'] = 1
|
|
stats['pdf-caching-timed-out'] = 1
|
|
|
- return callback(null, outputFiles)
|
|
|
|
|
|
|
+ return callback(null)
|
|
|
}
|
|
}
|
|
|
- if (err) return callback(err, outputFiles)
|
|
|
|
|
|
|
+ if (err) return callback(err)
|
|
|
const [
|
|
const [
|
|
|
contentRanges,
|
|
contentRanges,
|
|
|
newContentRanges,
|
|
newContentRanges,
|
|
@@ -399,7 +414,7 @@ module.exports = OutputCacheManager = {
|
|
|
startXRefTable,
|
|
startXRefTable,
|
|
|
] = result
|
|
] = result
|
|
|
|
|
|
|
|
- if (Settings.enablePdfCachingDark) {
|
|
|
|
|
|
|
+ if (enablePdfCachingDark) {
|
|
|
// In dark mode we are doing the computation only and do not emit
|
|
// In dark mode we are doing the computation only and do not emit
|
|
|
// any ranges to the frontend.
|
|
// any ranges to the frontend.
|
|
|
} else {
|
|
} else {
|
|
@@ -420,11 +435,11 @@ module.exports = OutputCacheManager = {
|
|
|
0
|
|
0
|
|
|
)
|
|
)
|
|
|
stats['pdf-caching-reclaimed-space'] = reclaimedSpace
|
|
stats['pdf-caching-reclaimed-space'] = reclaimedSpace
|
|
|
- callback(null, outputFiles)
|
|
|
|
|
|
|
+ callback(null)
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
} else {
|
|
} else {
|
|
|
- callback(null, outputFiles)
|
|
|
|
|
|
|
+ callback(null)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|