Просмотр исходного кода

Merge pull request #29891 from overleaf/bg-docupdater-make-max-unflushed-age-configurable

Make document-updater max unflushed age configurable via settings

GitOrigin-RevId: 3421f2467b7d8459ba8cdb1859e1b0695b0a01f3
Brian Gough 8 месяцев назад
Родитель
Сommit
a45c39389c

+ 1 - 1
services/document-updater/app/js/DocumentManager.js

@@ -13,7 +13,7 @@ const { getTotalSizeOfLines } = require('./Limits')
 const Settings = require('@overleaf/settings')
 const Settings = require('@overleaf/settings')
 const { StringFileData } = require('overleaf-editor-core')
 const { StringFileData } = require('overleaf-editor-core')
 
 
-const MAX_UNFLUSHED_AGE = 300 * 1000 // 5 mins, document should be flushed to mongo this time after a change
+const MAX_UNFLUSHED_AGE = Settings.maxUnflushedAgeMs // document should be flushed to mongo this time after a change
 
 
 const DocumentManager = {
 const DocumentManager = {
   /**
   /**

+ 3 - 0
services/document-updater/config/settings.defaults.js

@@ -188,6 +188,9 @@ module.exports = {
   gracefulShutdownDelayInMs:
   gracefulShutdownDelayInMs:
     parseInt(process.env.GRACEFUL_SHUTDOWN_DELAY_SECONDS ?? '10', 10) * 1000,
     parseInt(process.env.GRACEFUL_SHUTDOWN_DELAY_SECONDS ?? '10', 10) * 1000,
 
 
+  maxUnflushedAgeMs:
+    parseInt(process.env.MAX_UNFLUSHED_AGE_SECONDS ?? '300', 10) * 1000, // 5 mins by default
+
   shortHistoryQueues: (process.env.SHORT_HISTORY_QUEUES || '')
   shortHistoryQueues: (process.env.SHORT_HISTORY_QUEUES || '')
     .split(',')
     .split(',')
     .filter(s => !!s),
     .filter(s => !!s),

+ 3 - 2
services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js

@@ -58,6 +58,7 @@ describe('DocumentManager', function () {
     }
     }
     this.Settings = {
     this.Settings = {
       max_doc_length: 2 * 1024 * 1024, // 2mb
       max_doc_length: 2 * 1024 * 1024, // 2mb
+      maxUnflushedAgeMs: 300 * 1000, // 5 minutes
     }
     }
 
 
     this.DocumentManager = SandboxedModule.require(modulePath, {
     this.DocumentManager = SandboxedModule.require(modulePath, {
@@ -1030,7 +1031,7 @@ describe('DocumentManager', function () {
             ranges: this.ranges,
             ranges: this.ranges,
             projectHistoryId: this.projectHistoryId,
             projectHistoryId: this.projectHistoryId,
             pathname: this.pathname,
             pathname: this.pathname,
-            unflushedTime: Date.now() - 1e9,
+            unflushedTime: Date.now() - 2 * this.Settings.maxUnflushedAgeMs, // document is older than max unflushed age
             alreadyLoaded: true,
             alreadyLoaded: true,
           })
           })
           this.result = await this.DocumentManager.promises.getDocAndFlushIfOld(
           this.result = await this.DocumentManager.promises.getDocAndFlushIfOld(
@@ -1066,7 +1067,7 @@ describe('DocumentManager', function () {
             version: this.version,
             version: this.version,
             ranges: this.ranges,
             ranges: this.ranges,
             pathname: this.pathname,
             pathname: this.pathname,
-            unflushedTime: Date.now() - 100,
+            unflushedTime: Date.now() - 0.5 * this.Settings.maxUnflushedAgeMs, // document is not old enough to trigger flush
             alreadyLoaded: true,
             alreadyLoaded: true,
           })
           })
           this.result = await this.DocumentManager.promises.getDocAndFlushIfOld(
           this.result = await this.DocumentManager.promises.getDocAndFlushIfOld(