[misc] merge pdf caching into main (#4033)

* [frontend] WIP: pdf caching using service worker -- squashed

Ref: 920fbaa00b31530f7c457a2d93bad5e553798057
Co-Authored-By: Brian Gough <brian.gough@overleaf.com>
Co-Authored-By: Eric Mc Sween <eric.mcsween@overleaf.com>

* [misc] add contentId into the URL for protecting PDF stream contents

* [misc] gracefully handle missing ranges in serviceWorker

* [misc] support PDF stream caching for anonymous users

* [misc] polish header names and add URL to error message when fetch fails

* [misc] polish event handler registration

* [misc] limit serviceWorker scope to /project/ -- trailing slash

This will block the service worker from intercepting requests on the
 project dashboard.

* [misc] add per-request feature flag for enabling PDF stream caching

* [misc] expose compile stats and timings to the frontend

* [misc] serviceWorker: support clsiServerId and compileGroup url params

* [misc] serviceWorker: polish header maps

* [misc] serviceWorker: drop TODO for p-limit -- the browser has a queue

* [misc] serviceWorker: drop verbose log message on every fetch

* [misc] cut down size of diff in backend code

* [misc] add test case for forwarding of pdf caching and metrics details

* [misc] serviceWorker: drop all the log lines

* [misc] serviceWorker: add boundary guards to the compile request regex

Co-authored-by: Brian Gough <brian.gough@overleaf.com>
Co-authored-by: Eric Mc Sween <eric.mcsween@overleaf.com>
GitOrigin-RevId: 4b291b4a4f2866cf07bccf8ec9068f33bbfdc916
This commit is contained in:
Jakob Ackermann
2021-05-18 02:07:57 +00:00
committed by Copybot
co-authored by Brian Gough Eric Mc Sween
parent 2901de7830
commit 7db7cd4a49
13 changed files with 420 additions and 19 deletions
@@ -256,11 +256,19 @@ const ClsiManager = {
projectId,
response && response.compile && response.compile.outputFiles
)
const compile = (response && response.compile) || {}
const status = compile.status
const stats = compile.stats
const timings = compile.timings
const validationProblems = undefined
callback(
null,
response && response.compile && response.compile.status,
status,
outputFiles,
clsiServerId
clsiServerId,
validationProblems,
stats,
timings
)
})
}
@@ -496,6 +504,9 @@ const ClsiManager = {
url: Url.parse(file.url).path, // the location of the file on the clsi, excluding the host part
type: file.type,
build: file.build,
contentId: file.contentId,
ranges: file.ranges,
size: file.size,
})
}
return outputFiles
@@ -813,6 +824,8 @@ const ClsiManager = {
syncType: options.syncType,
syncState: options.syncState,
compileGroup: options.compileGroup,
enablePdfCaching:
(Settings.enablePdfCaching && options.enablePdfCaching) || false,
},
rootResourcePath,
resources,
@@ -46,9 +46,11 @@ module.exports = CompileController = {
res.setTimeout(COMPILE_TIMEOUT_MS)
const project_id = req.params.Project_id
const isAutoCompile = !!req.query.auto_compile
const enablePdfCaching = !!req.query.enable_pdf_caching
const user_id = AuthenticationController.getLoggedInUserId(req)
const options = {
isAutoCompile,
enablePdfCaching,
}
if (req.body.rootDoc_id) {
@@ -83,7 +85,9 @@ module.exports = CompileController = {
outputFiles,
clsiServerId,
limits,
validationProblems
validationProblems,
stats,
timings
) => {
if (error) {
Metrics.inc('compile-error')
@@ -96,6 +100,8 @@ module.exports = CompileController = {
compileGroup: limits != null ? limits.compileGroup : undefined,
clsiServerId,
validationProblems,
stats,
timings,
pdfDownloadDomain: Settings.pdfDownloadDomain,
})
}
@@ -94,7 +94,9 @@ module.exports = CompileManager = {
status,
outputFiles,
clsiServerId,
validationProblems
validationProblems,
stats,
timings
) {
if (error != null) {
return callback(error)
@@ -105,7 +107,9 @@ module.exports = CompileManager = {
outputFiles,
clsiServerId,
limits,
validationProblems
validationProblems,
stats,
timings
)
}
)
@@ -874,6 +874,9 @@ const ProjectController = {
),
showNewBinaryFileUI: shouldDisplayFeature('new_binary_file'),
showSymbolPalette: shouldDisplayFeature('symbol_palette'),
enablePdfCaching:
Settings.enablePdfCaching &&
shouldDisplayFeature('enable_pdf_caching', user.alphaProgram),
})
timer.done()
}
@@ -187,6 +187,7 @@ block append meta
meta(name="ol-showNewLogsUI" data-type="boolean" content=showNewLogsUI)
meta(name="ol-logsUISubvariant" content=logsUISubvariant)
meta(name="ol-showSymbolPalette" data-type="boolean" content=showSymbolPalette)
meta(name="ol-enablePdfCaching" data-type="boolean" content=enablePdfCaching)
- var fileActionI18n = ['edited', 'renamed', 'created', 'deleted'].reduce((acc, i) => {acc[i] = translate('file_action_' + i); return acc}, {})
meta(name="ol-fileActionI18n" data-type="json" content=fileActionI18n)