overleaf/services/web/scripts/count_files_in_projects.js
Simon Detheridge bbe9f9a620 Merge pull request #2798 from overleaf/spd-count-files
Add script to delete deleted-project data from filestore

GitOrigin-RevId: 9a2c5861edddf5ed26fc684257369fac4cf95475
2020-05-02 03:19:27 +00:00

47 lines
1.3 KiB
JavaScript

const readline = require('readline')
const ProjectEntityHandler = require('../app/src/Features/Project/ProjectEntityHandler')
const ProjectGetter = require('../app/src/Features/Project/ProjectGetter')
const Errors = require('../app/src/Features/Errors/Errors')
/* eslint-disable no-console */
async function countFiles() {
const rl = readline.createInterface({
input: process.stdin
})
for await (const projectId of rl) {
try {
const project = await ProjectGetter.promises.getProject(projectId)
if (!project) {
throw new Errors.NotFoundError('project not found')
}
const {
files,
docs
} = await ProjectEntityHandler.promises.getAllEntitiesFromProject(project)
console.error(
projectId,
files.length,
(project.deletedFiles && project.deletedFiles.length) || 0,
docs.length,
(project.deletedDocs && project.deletedDocs.length) || 0
)
} catch (err) {
if (err instanceof Errors.NotFoundError) {
console.error(projectId, 'NOTFOUND')
} else {
console.log(projectId, 'ERROR', err.name, err.message)
}
}
}
}
countFiles()
.then(() => {
process.exit(0)
})
.catch(err => {
console.log('Aiee, something went wrong!', err)
process.exit(1)
})