diff --git a/services/document-updater/scripts/remove_deleted_docs.js b/services/document-updater/scripts/remove_deleted_docs.js index a69807119f..7f671d3a05 100644 --- a/services/document-updater/scripts/remove_deleted_docs.js +++ b/services/document-updater/scripts/remove_deleted_docs.js @@ -7,11 +7,6 @@ const keys = Settings.redis.documentupdater.key_schema const ProjectFlusher = require('../app/js/ProjectFlusher') const RedisManager = require('../app/js/RedisManager') const { mongoClient, db, ObjectId } = require('../app/js/mongodb') -const util = require('node:util') -const getDoc = util.promisify((projectId, docId, cb) => - RedisManager.getDoc(projectId, docId, (err, ...args) => cb(err, args)) -) -const removeDocFromMemory = util.promisify(RedisManager.removeDocFromMemory) const summary = { totalDocs: 0, deletedDocs: 0, skippedDocs: 0 } @@ -33,8 +28,8 @@ async function removeDeletedDocs(dockeys, options) { async function removeDeletedDoc(docId, options) { const projectId = await rclient.get(keys.projectKey({ doc_id: docId })) - const [ - docLines, + const { + lines: docLines, version, ranges, pathname, @@ -42,7 +37,9 @@ async function removeDeletedDoc(docId, options) { unflushedTime, lastUpdatedAt, lastUpdatedBy, - ] = await getDoc(projectId, docId) + historyRangesSupport, + resolvedCommentIds, + } = await RedisManager.promises.getDoc(projectId, docId) const project = await db.projects.findOne({ _id: new ObjectId(projectId) }) @@ -64,6 +61,8 @@ async function removeDeletedDoc(docId, options) { unflushedTime, lastUpdatedAt, lastUpdatedBy, + historyRangesSupport, + resolvedCommentIds, }, 'refusing to delete doc, project contains docId' ) @@ -82,6 +81,8 @@ async function removeDeletedDoc(docId, options) { unflushedTime, lastUpdatedAt, lastUpdatedBy, + historyRangesSupport, + resolvedCommentIds, }, 'refusing to delete doc, project still exists' ) @@ -105,6 +106,8 @@ async function removeDeletedDoc(docId, options) { unflushedTime, lastUpdatedAt, lastUpdatedBy, + historyRangesSupport, + resolvedCommentIds, status, summary, }, @@ -112,7 +115,6 @@ async function removeDeletedDoc(docId, options) { ) return } - removeDocFromMemory(projectId, docId) logger.info( { projectId, @@ -125,11 +127,14 @@ async function removeDeletedDoc(docId, options) { unflushedTime, lastUpdatedAt, lastUpdatedBy, + historyRangesSupport, + resolvedCommentIds, status, summary, }, - 'removed doc from redis' + 'removing doc from redis' ) + await RedisManager.promises.removeDocFromMemory(projectId, docId) } async function findAndProcessDocs(options) { @@ -148,8 +153,26 @@ async function findAndProcessDocs(options) { } while (cursor !== '0') } -findAndProcessDocs({ limit: 1000, dryRun: process.env.DRY_RUN !== 'false' }) - .then(result => { +async function main() { + const options = { + limit: 1000, + dryRun: process.env.DRY_RUN !== 'false', + } + if (process.argv.length > 2) { + const docId = process.argv[process.argv.length - 1] + if (!ObjectId.isValid(docId)) { + throw new Error( + 'bad docId: usage: $ node scripts/remove_deleted_docs.js [DOC_ID]' + ) + } + await removeDeletedDoc(docId, options) + } else { + await findAndProcessDocs(options) + } +} + +main() + .then(() => { rclient.quit() mongoClient.close() console.log('DONE')