Merge pull request #24790 from overleaf/ls-use-script-runner

Update some scripts to use Script Runner

GitOrigin-RevId: aaa11f94dcfd328c158bb02d1b9fb2adfb1bb146
This commit is contained in:
Liangjun Song
2025-05-22 11:51:53 +01:00
committed by Copybot
parent d0010217cd
commit 2f87db9c0d
62 changed files with 225 additions and 112 deletions

View File

@@ -35,6 +35,7 @@ let BATCHED_UPDATE_RUNNING = false
* @property {string} [BATCH_RANGE_START]
* @property {string} [BATCH_SIZE]
* @property {string} [VERBOSE_LOGGING]
* @property {(progress: string) => Promise<void>} [trackProgress]
*/
/**
@@ -210,7 +211,7 @@ async function batchedUpdate(
update,
projection,
findOptions,
batchedUpdateOptions
batchedUpdateOptions = {}
) {
// only a single batchedUpdate can run at a time due to global variables
if (BATCHED_UPDATE_RUNNING) {
@@ -226,6 +227,8 @@ async function batchedUpdate(
return 0
}
refreshGlobalOptionsForBatchedUpdate(batchedUpdateOptions)
const { trackProgress = async progress => console.warn(progress) } =
batchedUpdateOptions
findOptions = findOptions || {}
findOptions.readPreference = READ_PREFERENCE_SECONDARY
@@ -255,9 +258,10 @@ async function batchedUpdate(
nextBatch.map(entry => entry._id)
)}`
)
} else {
console.error(`Running update on batch ending ${renderObjectId(end)}`)
}
await trackProgress(
`Running update on batch ending ${renderObjectId(end)}`
)
if (typeof update === 'function') {
await update(nextBatch)
@@ -265,7 +269,7 @@ async function batchedUpdate(
await performUpdate(collection, nextBatch, update)
}
}
console.error(`Completed batch ending ${renderObjectId(end)}`)
await trackProgress(`Completed batch ending ${renderObjectId(end)}`)
start = end
}
return updated