From a45c39389ca42fdc586d1836282d4f2d785d0228 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 5 Dec 2025 11:48:35 +0000 Subject: [PATCH] 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 --- services/document-updater/app/js/DocumentManager.js | 2 +- services/document-updater/config/settings.defaults.js | 3 +++ .../test/unit/js/DocumentManager/DocumentManagerTests.js | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/document-updater/app/js/DocumentManager.js b/services/document-updater/app/js/DocumentManager.js index dd91f8246c..cdfdadc071 100644 --- a/services/document-updater/app/js/DocumentManager.js +++ b/services/document-updater/app/js/DocumentManager.js @@ -13,7 +13,7 @@ const { getTotalSizeOfLines } = require('./Limits') const Settings = require('@overleaf/settings') 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 = { /** diff --git a/services/document-updater/config/settings.defaults.js b/services/document-updater/config/settings.defaults.js index e9b16c0140..af592a27ba 100755 --- a/services/document-updater/config/settings.defaults.js +++ b/services/document-updater/config/settings.defaults.js @@ -188,6 +188,9 @@ module.exports = { gracefulShutdownDelayInMs: 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 || '') .split(',') .filter(s => !!s), diff --git a/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js b/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js index 7a394c347b..da99b37f52 100644 --- a/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js +++ b/services/document-updater/test/unit/js/DocumentManager/DocumentManagerTests.js @@ -58,6 +58,7 @@ describe('DocumentManager', function () { } this.Settings = { max_doc_length: 2 * 1024 * 1024, // 2mb + maxUnflushedAgeMs: 300 * 1000, // 5 minutes } this.DocumentManager = SandboxedModule.require(modulePath, { @@ -1030,7 +1031,7 @@ describe('DocumentManager', function () { ranges: this.ranges, projectHistoryId: this.projectHistoryId, pathname: this.pathname, - unflushedTime: Date.now() - 1e9, + unflushedTime: Date.now() - 2 * this.Settings.maxUnflushedAgeMs, // document is older than max unflushed age alreadyLoaded: true, }) this.result = await this.DocumentManager.promises.getDocAndFlushIfOld( @@ -1066,7 +1067,7 @@ describe('DocumentManager', function () { version: this.version, ranges: this.ranges, 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, }) this.result = await this.DocumentManager.promises.getDocAndFlushIfOld(