Procházet zdrojové kódy

[clsi-cache] only use sharding from updated project editor tabs (#25326)

GitOrigin-RevId: 1754276bed3186c0536055c983e32476cc90d416
Jakob Ackermann před 1 rokem
rodič
revize
6881ba956a

+ 8 - 1
services/clsi/app/js/CLSICacheHandler.js

@@ -41,6 +41,7 @@ function getShard(projectId) {
  * @param {string} editorId
  * @param {[{path: string}]} outputFiles
  * @param {string} compileGroup
+ * @param {boolean} clsiCacheSharded
  * @param {Record<string, any>} options
  * @return {string | undefined}
  */
@@ -51,11 +52,17 @@ function notifyCLSICacheAboutBuild({
   editorId,
   outputFiles,
   compileGroup,
+  clsiCacheSharded,
   options,
 }) {
   if (!Settings.apis.clsiCache.enabled) return undefined
   if (!OBJECT_ID_REGEX.test(projectId)) return undefined
-  const { url, shard } = getShard(projectId)
+  let { url, shard } = getShard(projectId)
+  if (!clsiCacheSharded) {
+    // Client is not aware of sharding yet.
+    url = Settings.apis.clsiCache.url
+    shard = 'cache'
+  }
 
   /**
    * @param {[{path: string}]} files

+ 1 - 0
services/clsi/app/js/CompileController.js

@@ -125,6 +125,7 @@ function compile(req, res, next) {
                 editorId: request.editorId,
                 outputFiles,
                 compileGroup: request.compileGroup,
+                clsiCacheSharded: request.clsiCacheSharded,
                 options: {
                   compiler: request.compiler,
                   draft: request.draft,

+ 8 - 0
services/clsi/app/js/RequestParser.js

@@ -90,6 +90,14 @@ function parse(body, callback) {
         type: 'boolean',
       }
     )
+    response.clsiCacheSharded = _parseAttribute(
+      'clsiCacheSharded',
+      compile.options.clsiCacheSharded,
+      {
+        default: false,
+        type: 'boolean',
+      }
+    )
     response.check = _parseAttribute('check', compile.options.check, {
       type: 'string',
     })

+ 1 - 0
services/clsi/config/settings.defaults.js

@@ -61,6 +61,7 @@ module.exports = {
     },
     clsiCache: {
       enabled: !!(process.env.CLSI_CACHE_SHARDS || process.env.CLSI_CACHE_HOST),
+      url: `http://${process.env.CLSI_CACHE_HOST}:3044`,
       shards: process.env.CLSI_CACHE_SHARDS
         ? JSON.parse(process.env.CLSI_CACHE_SHARDS)
         : [

+ 1 - 0
services/web/app/src/Features/Compile/ClsiManager.js

@@ -781,6 +781,7 @@ function _finaliseRequest(projectId, options, project, docs, files) {
         imageName: project.imageName,
         draft: Boolean(options.draft),
         stopOnFirstError: Boolean(options.stopOnFirstError),
+        clsiCacheSharded: Boolean(options.clsiCacheSharded),
         check: options.check,
         syncType: options.syncType,
         syncState: options.syncState,

+ 2 - 0
services/web/app/src/Features/Compile/CompileController.js

@@ -132,12 +132,14 @@ module.exports = CompileController = {
     const isAutoCompile = !!req.query.auto_compile
     const fileLineErrors = !!req.query.file_line_errors
     const stopOnFirstError = !!req.body.stopOnFirstError
+    const clsiCacheSharded = !!req.body.clsiCacheSharded
     const userId = SessionManager.getLoggedInUserId(req.session)
     const options = {
       isAutoCompile,
       fileLineErrors,
       stopOnFirstError,
       editorId: req.body.editorId,
+      clsiCacheSharded,
     }
 
     if (req.body.rootDoc_id) {

+ 1 - 0
services/web/frontend/js/features/pdf-preview/util/compiler.js

@@ -110,6 +110,7 @@ export default class DocumentCompiler {
         incrementalCompilesEnabled: !this.error,
         stopOnFirstError: options.stopOnFirstError,
         editorId: EDITOR_SESSION_ID,
+        clsiCacheSharded: true,
       }
 
       const data = await postJSON(

+ 4 - 0
services/web/test/unit/src/Compile/CompileControllerTests.js

@@ -250,6 +250,7 @@ describe('CompileController', function () {
             fileLineErrors: false,
             stopOnFirstError: false,
             editorId: undefined,
+            clsiCacheSharded: false,
           }
         )
       })
@@ -293,6 +294,7 @@ describe('CompileController', function () {
             fileLineErrors: false,
             stopOnFirstError: false,
             editorId: undefined,
+            clsiCacheSharded: false,
           }
         )
       })
@@ -318,6 +320,7 @@ describe('CompileController', function () {
             fileLineErrors: false,
             stopOnFirstError: false,
             editorId: undefined,
+            clsiCacheSharded: false,
           }
         )
       })
@@ -342,6 +345,7 @@ describe('CompileController', function () {
             fileLineErrors: false,
             stopOnFirstError: false,
             editorId: 'the-editor-id',
+            clsiCacheSharded: false,
           }
         )
       })