From 2b47f38510cd56f3dd84d89ac32d8e68c99e3fe9 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 28 Feb 2025 13:02:05 +0000 Subject: [PATCH] Merge pull request #23977 from overleaf/bg-backup-worker-load-global-blobs ensure global blobs are loaded in backup worker GitOrigin-RevId: b80791ef38e7fa8db364bdd3a9c461757778409d --- services/history-v1/storage/scripts/backup.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/history-v1/storage/scripts/backup.mjs b/services/history-v1/storage/scripts/backup.mjs index a89950e416..414e5bb079 100644 --- a/services/history-v1/storage/scripts/backup.mjs +++ b/services/history-v1/storage/scripts/backup.mjs @@ -43,6 +43,15 @@ import { text } from 'node:stream/consumers' import { fromStream as blobHashFromStream } from '../lib/blob_hash.js' import { NotFoundError } from '@overleaf/object-persistor/src/Errors.js' +// Create a singleton promise that loads global blobs once +let globalBlobsPromise = null +function ensureGlobalBlobsLoaded() { + if (!globalBlobsPromise) { + globalBlobsPromise = loadGlobalBlobs() + } + return globalBlobsPromise +} + EventEmitter.defaultMaxListeners = 20 logger.initialize('history-v1-backup') @@ -497,6 +506,7 @@ function makeChunkKey(projectId, startVersion) { } export async function backupProject(projectId, options) { + await ensureGlobalBlobsLoaded() // FIXME: flush the project first! // Let's assume the the flush happens externally and triggers this backup const backupStartTime = new Date() @@ -641,6 +651,7 @@ function convertToISODate(dateStr) { } export async function initializeProjects(options) { + await ensureGlobalBlobsLoaded() const limiter = pLimit(BATCH_CONCURRENCY) async function processBatch(batch) { @@ -920,7 +931,7 @@ async function compareAllProjects(options) { async function main() { const options = handleOptions() - await loadGlobalBlobs() + await ensureGlobalBlobsLoaded() const projectId = options.projectId if (options.status) {