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
This commit is contained in:
Brian Gough
2025-12-05 11:48:35 +00:00
committed by Copybot
parent a75c6a2c63
commit a45c39389c
3 changed files with 7 additions and 3 deletions

View File

@@ -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 = {
/**

View File

@@ -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),

View File

@@ -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(