mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-26 13:47:26 +03:00
Add DB compact tool (#6125)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
71c2fa0750
commit
9aad4a4561
@ -237,6 +237,42 @@ export function devTool (
|
||||
})
|
||||
})
|
||||
|
||||
program
|
||||
.command('compact-db')
|
||||
.description('compact all db collections')
|
||||
.option('-w, --workspace <workspace>', 'A selected "workspace" only', '')
|
||||
.action(async (cmd: { workspace: string }) => {
|
||||
const { mongodbUri } = prepareTools()
|
||||
await withDatabase(mongodbUri, async (db, client) => {
|
||||
console.log('compacting db ...')
|
||||
let gtotal: number = 0
|
||||
try {
|
||||
const workspaces = await listWorkspacesPure(db, productId)
|
||||
for (const workspace of workspaces) {
|
||||
if (cmd.workspace !== '' && workspace.workspace !== cmd.workspace) {
|
||||
continue
|
||||
}
|
||||
let total: number = 0
|
||||
const wsDb = getWorkspaceDB(client, { name: workspace.workspace, productId })
|
||||
const collections = wsDb.listCollections()
|
||||
while (true) {
|
||||
const collInfo = await collections.next()
|
||||
if (collInfo === null) {
|
||||
break
|
||||
}
|
||||
const result = await wsDb.command({ compact: collInfo.name })
|
||||
total += result.bytesFreed
|
||||
}
|
||||
gtotal += total
|
||||
console.log('total feed for db', workspace.workspaceName, Math.round(total / (1024 * 1024)))
|
||||
}
|
||||
console.log('global total feed', Math.round(gtotal / (1024 * 1024)))
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
program
|
||||
.command('assign-workspace <email> <workspace>')
|
||||
.description('assign workspace')
|
||||
|
Loading…
Reference in New Issue
Block a user