Merge pull request #21706 from overleaf/bg-clear-projects-from-docupdater

clear inactive projects from docupdater when archiving

GitOrigin-RevId: 8fb11e6ebd29dfaafb62c10e07e774b90301b5ae
This commit is contained in:
Brian Gough
2024-12-06 09:56:03 +00:00
committed by Copybot
parent d5b943fe8e
commit 0d1dfd66d7
2 changed files with 48 additions and 1 deletions
@@ -1,12 +1,15 @@
const OError = require('@overleaf/o-error')
const logger = require('@overleaf/logger')
const DocstoreManager = require('../Docstore/DocstoreManager')
const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
const ProjectGetter = require('../Project/ProjectGetter')
const ProjectUpdateHandler = require('../Project/ProjectUpdateHandler')
const { Project } = require('../../models/Project')
const { ObjectId } = require('mongodb-legacy')
const Modules = require('../../infrastructure/Modules')
const { READ_PREFERENCE_SECONDARY } = require('../../infrastructure/mongodb')
const { callbackifyAll } = require('@overleaf/promise-utils')
const Metrics = require('@overleaf/metrics')
const MILISECONDS_IN_DAY = 86400000
const InactiveProjectManager = {
@@ -93,6 +96,26 @@ const InactiveProjectManager = {
async deactivateProject(projectId) {
logger.debug({ projectId }, 'deactivating inactive project')
// ensure project is removed from document updater (also flushes updates to history)
try {
await DocumentUpdaterHandler.promises.flushProjectToMongoAndDelete(
projectId
)
} catch (err) {
logger.warn(
{ err, projectId },
'error flushing project to mongo when archiving'
)
Metrics.inc('inactive-project', 1, {
method: 'archive',
status: 'flush-error',
})
throw err
}
await Modules.promises.hooks.fire('deactivateProject', projectId)
// now archive the project and mark it as inactive
try {
await DocstoreManager.promises.archiveProject(projectId)
await ProjectUpdateHandler.promises.markAsInactive(projectId)