Merge pull request #25889 from overleaf/jpa-web-wait-for-mongo

[web] wait for DB before fetching global blobs

GitOrigin-RevId: 2beefd39ae4be4d233e2aac018d471bf949faea2
This commit is contained in:
Miguel Serrano
2025-05-23 12:46:16 +02:00
committed by Copybot
parent 1587a6d861
commit fe124e5656
3 changed files with 10 additions and 4 deletions
@@ -11,7 +11,7 @@ const OError = require('@overleaf/o-error')
const UserGetter = require('../User/UserGetter')
const ProjectGetter = require('../Project/ProjectGetter')
const HistoryBackupDeletionHandler = require('./HistoryBackupDeletionHandler')
const { db, ObjectId } = require('../../infrastructure/mongodb')
const { db, ObjectId, waitForDb } = require('../../infrastructure/mongodb')
const Metrics = require('@overleaf/metrics')
const logger = require('@overleaf/logger')
const { NotFoundError } = require('../Errors/Errors')
@@ -50,6 +50,7 @@ function getBlobLocation(projectId, hash) {
}
async function loadGlobalBlobs() {
await waitForDb() // CHANGE FROM SOURCE: wait for db before running query.
const blobs = db.projectHistoryGlobalBlobs.find()
for await (const blob of blobs) {
GLOBAL_BLOBS.add(blob._id) // CHANGE FROM SOURCE: only store hashes.
@@ -130,10 +130,15 @@ async function getCollectionInternal(name) {
return internalDb.collection(name)
}
async function waitForDb() {
await connectionPromise
}
module.exports = {
db,
ObjectId,
connectionPromise,
waitForDb,
getCollectionNames,
getCollectionInternal,
cleanupTestDatabase,
@@ -3,9 +3,9 @@ const sinon = require('sinon')
const SandboxedModule = require('sandboxed-module')
const { ObjectId } = require('mongodb-legacy')
const {
connectionPromise,
cleanupTestDatabase,
db,
waitForDb,
} = require('../../../../app/src/infrastructure/mongodb')
const MODULE_PATH = '../../../../app/src/Features/History/HistoryManager'
@@ -19,7 +19,7 @@ const GLOBAL_BLOBS = {
describe('HistoryManager', function () {
before(async function () {
await connectionPromise
await waitForDb()
})
before(cleanupTestDatabase)
before(async function () {
@@ -90,7 +90,7 @@ describe('HistoryManager', function () {
this.HistoryManager = SandboxedModule.require(MODULE_PATH, {
requires: {
'../../infrastructure/mongodb': { ObjectId, db },
'../../infrastructure/mongodb': { ObjectId, db, waitForDb },
'@overleaf/fetch-utils': this.FetchUtils,
'@overleaf/settings': this.settings,
'../User/UserGetter': this.UserGetter,