|
|
@@ -42,6 +42,10 @@ const CLSI_COOKIES_ENABLED = (Settings.clsiCookie?.key ?? '') !== ''
|
|
|
// The timeout in services/clsi/app.js is 10 minutes, so we'll be on the safe side with 12 minutes
|
|
|
const COMPILE_REQUEST_TIMEOUT_MS = 12 * 60 * 1000
|
|
|
|
|
|
+// Enable clsi-cache for all compiles for 20min when detecting low capacity.
|
|
|
+const ENABLE_COMPILE_FROM_CACHE_ON_503_MS = 20 * 60 * 1000
|
|
|
+let enableCompileFromCacheUntil = 0
|
|
|
+
|
|
|
function _baseHistoryVersionKey(projectId, userId) {
|
|
|
return `baseHistoryVersion:${projectId}:${userId}`
|
|
|
}
|
|
|
@@ -678,6 +682,8 @@ async function _postToClsi(
|
|
|
} else if (err.response.status === 423) {
|
|
|
return { response: { compile: { status: 'compile-in-progress' } } }
|
|
|
} else if (err.response.status === 503) {
|
|
|
+ enableCompileFromCacheUntil =
|
|
|
+ Date.now() + ENABLE_COMPILE_FROM_CACHE_ON_503_MS
|
|
|
return { response: { compile: { status: 'unavailable' } } }
|
|
|
} else if (err.response.status === 504) {
|
|
|
return { response: { compile: { status: 'timedout' } } }
|
|
|
@@ -1104,11 +1110,20 @@ function _finaliseRequest(projectId, options, project, docs, files) {
|
|
|
compileGroup: options.compileGroup,
|
|
|
// Overleaf alpha/staff users get compileGroup=alpha (via getProjectCompileLimits in CompileManager), enroll them into the premium rollout of clsi-cache.
|
|
|
compileFromClsiCache:
|
|
|
- ['alpha', 'priority'].includes(options.compileGroup) &&
|
|
|
+ // enable for premium compiles
|
|
|
+ (['alpha', 'priority'].includes(options.compileGroup) ||
|
|
|
+ // enable for free for short period when we saw low capacity
|
|
|
+ enableCompileFromCacheUntil > Date.now()) &&
|
|
|
options.compileFromClsiCache,
|
|
|
populateClsiCache:
|
|
|
+ // enable for premium compiles
|
|
|
(['alpha', 'priority'].includes(options.compileGroup) ||
|
|
|
- options.metricsPath === 'clsi-cache-template') &&
|
|
|
+ // enable when populating template cache
|
|
|
+ options.metricsPath === 'clsi-cache-template' ||
|
|
|
+ // populate indefinitely for free when we saw low capacity
|
|
|
+ !!enableCompileFromCacheUntil ||
|
|
|
+ // populate with compile from history enabled to re-use snapshot from cache
|
|
|
+ !!options.rawChangeOperations) &&
|
|
|
options.populateClsiCache,
|
|
|
enablePdfCaching:
|
|
|
(Settings.enablePdfCaching && options.enablePdfCaching) || false,
|