Merge pull request #12986 from overleaf/jpa-docstore-archiving-disabled

[docstore] skip mongo/object-persistor calls when archiving is disabled

GitOrigin-RevId: 71bb7d77e987d6f32e37fd888311b6cc2a461170
This commit is contained in:
Jakob Ackermann
2023-05-09 08:04:09 +00:00
committed by Copybot
parent 92ade70601
commit 5714deaa08
5 changed files with 132 additions and 2 deletions
@@ -33,6 +33,10 @@ module.exports = {
}
async function archiveAllDocs(projectId) {
if (!_isArchivingEnabled()) {
return
}
const docIds = await MongoManager.getNonArchivedProjectDocIds(projectId)
await pMap(docIds, docId => archiveDoc(projectId, docId), {
concurrency: PARALLEL_JOBS,
@@ -40,6 +44,10 @@ async function archiveAllDocs(projectId) {
}
async function archiveDoc(projectId, docId) {
if (!_isArchivingEnabled()) {
return
}
const doc = await MongoManager.getDocForArchiving(projectId, docId)
if (!doc) {
@@ -92,6 +100,10 @@ async function archiveDoc(projectId, docId) {
}
async function unArchiveAllDocs(projectId) {
if (!_isArchivingEnabled()) {
return
}
while (true) {
let docs
if (Settings.docstore.keepSoftDeletedDocsArchived) {
@@ -150,6 +162,13 @@ async function unarchiveDoc(projectId, docId) {
// The doc is already unarchived
return
}
if (!_isArchivingEnabled()) {
throw new Error(
'found archived doc, but archiving backend is not configured'
)
}
const archivedDoc = await getDoc(projectId, docId)
if (archivedDoc.rev == null) {
// Older archived docs didn't have a rev. Assume that the rev of the
+4 -1
View File
@@ -4,6 +4,9 @@ const persistorSettings = settings.docstore
persistorSettings.Metrics = require('@overleaf/metrics')
const ObjectPersistor = require('@overleaf/object-persistor')
const persistor = ObjectPersistor(persistorSettings)
const AbstractPersistor = require('@overleaf/object-persistor/src/AbstractPersistor')
const persistor = settings.docstore.backend
? ObjectPersistor(persistorSettings)
: new AbstractPersistor()
module.exports = persistor