Merge pull request #5917 from overleaf/bg-clean-up-pathname-script

[document-updater] clean up empty pathname script

GitOrigin-RevId: 6d7e47081de892e96ba93ca273662ec4397df796
This commit is contained in:
Brian Gough 2021-11-25 14:08:16 +00:00 committed by Copybot
parent 18ecbf37e6
commit a757ed898b

View file

@ -6,25 +6,15 @@ const rclient = require('@overleaf/redis-wrapper').createClient(
const keys = Settings.redis.documentupdater.key_schema const keys = Settings.redis.documentupdater.key_schema
const ProjectFlusher = require('app/js/ProjectFlusher') const ProjectFlusher = require('app/js/ProjectFlusher')
const DocumentManager = require('app/js/DocumentManager') const DocumentManager = require('app/js/DocumentManager')
// const RedisManager = require('app/js/RedisManager')
const util = require('util') const util = require('util')
const flushAndDeleteDocWithLock = util.promisify( const flushAndDeleteDocWithLock = util.promisify(
DocumentManager.flushAndDeleteDocWithLock DocumentManager.flushAndDeleteDocWithLock
) )
// const getDoc = util.promisify((projectId, docId, cb) => {
// RedisManager.getDoc(projectId, docId, (err, ...results) => {
// cb(err, results)
// })
// })
// const removeDocFromMemory = util.promisify(RedisManager.removeDocFromMemory)
async function flushAndDeleteDocs(dockeys, options) { async function flushAndDeleteDocs(dockeys, options) {
logger.debug({ dockeys }, 'trying keys')
const docIds = ProjectFlusher._extractIds(dockeys) const docIds = ProjectFlusher._extractIds(dockeys)
for (const docId of docIds) { for (const docId of docIds) {
const pathname = await rclient.get(keys.pathname({ doc_id: docId })) const pathname = await rclient.get(keys.pathname({ doc_id: docId }))
logger.debug({ docId, pathname }, 'checking doc')
if (!pathname) { if (!pathname) {
const projectId = await rclient.get(keys.projectKey({ doc_id: docId })) const projectId = await rclient.get(keys.projectKey({ doc_id: docId }))
if (!projectId) { if (!projectId) {
@ -40,54 +30,6 @@ async function flushAndDeleteDocs(dockeys, options) {
} }
} }
// async function deleteDanglingDoc(projectId, docId, pathname, options) {
// const [
// // eslint-disable-next-line no-unused-vars
// _docLines,
// version,
// // eslint-disable-next-line no-unused-vars
// _ranges,
// // eslint-disable-next-line no-unused-vars
// _pathname,
// projectHistoryId,
// unflushedTime,
// lastUpdatedAt,
// lastUpdatedBy,
// ] = await getDoc(projectId, docId)
// logger.warn(
// {
// projectId,
// docId,
// pathname,
// version,
// projectHistoryId,
// unflushedTime,
// lastUpdatedAt,
// lastUpdatedBy,
// },
// 'missing project id'
// )
// if (options.dryRun) {
// logger.info(
// { projectId, docId, pathname },
// 'dry run mode - would delete doc with empty pathname and project id'
// )
// return
// }
// logger.info(
// { projectId, docId, pathname },
// 'deleting doc with empty pathname and project id'
// )
// try {
// await removeDocFromMemory(projectId, docId)
// } catch (err) {
// logger.error(
// { projectId, docId, pathname, err },
// 'error deleting doc with empty pathname and project id'
// )
// }
// }
async function flushAndDeleteDoc(projectId, docId, pathname, options) { async function flushAndDeleteDoc(projectId, docId, pathname, options) {
if (options.dryRun) { if (options.dryRun) {
logger.info( logger.info(
@ -121,14 +63,14 @@ async function cleanUpDocs(options) {
'COUNT', 'COUNT',
options.limit options.limit
) )
logger.debug({ count: doclinesKeys.length }, 'found docs')
await flushAndDeleteDocs(doclinesKeys, options) await flushAndDeleteDocs(doclinesKeys, options)
cursor = newCursor cursor = newCursor
} while (cursor !== '0') } while (cursor !== '0')
} }
cleanUpDocs({ limit: 1000, dryRun: true }) cleanUpDocs({ limit: 1000, dryRun: process.env.DRY_RUN !== 'false' })
.then(result => { .then(result => {
rclient.quit()
console.log('DONE') console.log('DONE')
}) })
.catch(function (error) { .catch(function (error) {