Quellcode durchsuchen

[history-v1] Disable backups on CE/SP (#25591)

Disables backup when `backupStore` is not present,
as it's the case for CE/SP

GitOrigin-RevId: a920f041c639e599084fa97d2ef2643a01da70e3
Miguel Serrano vor 1 Jahr
Ursprung
Commit
85533a36e9

+ 7 - 5
services/history-v1/api/controllers/projects.js

@@ -255,11 +255,13 @@ async function createProjectBlob(req, res, next) {
     const blobStore = new BlobStore(projectId)
     const newBlob = await blobStore.putFile(tmpPath)
 
-    try {
-      const { backupBlob } = await import('../../storage/lib/backupBlob.mjs')
-      await backupBlob(projectId, newBlob, tmpPath)
-    } catch (error) {
-      logger.warn({ error, projectId, hash }, 'Failed to backup blob')
+    if (config.has('backupStore')) {
+      try {
+        const { backupBlob } = await import('../../storage/lib/backupBlob.mjs')
+        await backupBlob(projectId, newBlob, tmpPath)
+      } catch (error) {
+        logger.warn({ error, projectId, hash }, 'Failed to backup blob')
+      }
     }
     res.status(HTTPStatus.CREATED).end()
   })

+ 4 - 0
services/history-v1/storage/lib/chunk_store/mongo.js

@@ -3,6 +3,7 @@
 const { ObjectId, ReadPreference, MongoError } = require('mongodb')
 const { Chunk } = require('overleaf-editor-core')
 const OError = require('@overleaf/o-error')
+const config = require('config')
 const assert = require('../assert')
 const mongodb = require('../mongodb')
 const { ChunkVersionConflictError } = require('./errors')
@@ -259,6 +260,9 @@ async function updateProjectRecord(
   earliestChangeTimestamp,
   mongoOpts = {}
 ) {
+  if (!config.has('backupStore')) {
+    return
+  }
   // record the end version against the project
   await mongodb.projects.updateOne(
     {

+ 4 - 0
services/history-v1/test/acceptance/js/storage/support/cleanup.js

@@ -64,6 +64,10 @@ async function clearBucket(name) {
 let s3PersistorForBackupCleanup
 
 async function cleanupBackup() {
+  if (!config.has('backupStore')) {
+    return
+  }
+
   // The backupPersistor refuses to delete short prefixes. Use a low-level S3 persistor.
   if (!s3PersistorForBackupCleanup) {
     const { backupPersistor } = await import(