mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 06:33:42 +00:00
Merge pull request #2964 from overleaf/em-expire-projects
Limit batch size when expiring projects GitOrigin-RevId: 492c318e3f07c08b451d0894ff2754402677f75f
This commit is contained in:
parent
1012dbc3c4
commit
6be41f858a
1 changed files with 17 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
|||
const _ = require('lodash')
|
||||
const { db, ObjectId } = require('../../infrastructure/mongojs')
|
||||
const { callbackify } = require('util')
|
||||
const { Project } = require('../../models/Project')
|
||||
|
@ -18,6 +19,7 @@ const moment = require('moment')
|
|||
const { promiseMapWithLimit } = require('../../util/promises')
|
||||
|
||||
const EXPIRE_PROJECTS_AFTER_DAYS = 90
|
||||
const PROJECT_EXPIRATION_BATCH_SIZE = 10000
|
||||
|
||||
module.exports = {
|
||||
markAsDeletedByExternalSource: callbackify(markAsDeletedByExternalSource),
|
||||
|
@ -79,14 +81,22 @@ async function deleteUsersProjects(userId) {
|
|||
}
|
||||
|
||||
async function expireDeletedProjectsAfterDuration() {
|
||||
const deletedProjects = await DeletedProject.find({
|
||||
'deleterData.deletedAt': {
|
||||
$lt: new Date(moment().subtract(EXPIRE_PROJECTS_AFTER_DAYS, 'days'))
|
||||
const deletedProjects = await DeletedProject.find(
|
||||
{
|
||||
'deleterData.deletedAt': {
|
||||
$lt: new Date(moment().subtract(EXPIRE_PROJECTS_AFTER_DAYS, 'days'))
|
||||
},
|
||||
project: { $ne: null }
|
||||
},
|
||||
project: { $ne: null }
|
||||
})
|
||||
for (const deletedProject of deletedProjects) {
|
||||
await expireDeletedProject(deletedProject.deleterData.deletedProjectId)
|
||||
{ 'deleterData.deletedProjectId': 1 }
|
||||
).limit(PROJECT_EXPIRATION_BATCH_SIZE)
|
||||
const projectIds = _.shuffle(
|
||||
deletedProjects.map(
|
||||
deletedProject => deletedProject.deleterData.deletedProjectId
|
||||
)
|
||||
)
|
||||
for (const projectId of projectIds) {
|
||||
await expireDeletedProject(projectId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue