From 56d05e28f79ccb34477c8410333c511146d6da32 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 8 Dec 2023 19:29:25 +0600 Subject: [PATCH] Fix bw tool (#4167) Signed-off-by: Denis Bykhov --- dev/tool/src/clean.ts | 19 +++++++++++++++++++ dev/tool/src/index.ts | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/dev/tool/src/clean.ts b/dev/tool/src/clean.ts index 5f36819fc2..f6d8d986be 100644 --- a/dev/tool/src/clean.ts +++ b/dev/tool/src/clean.ts @@ -145,6 +145,25 @@ export async function cleanWorkspace ( } } +export async function fixMinioBW (workspaceId: WorkspaceId, minio: MinioService): Promise { + console.log('try clean bw miniature for ', workspaceId.name) + const from = new Date(new Date().setDate(new Date().getDate() - 7)) + const list = await minio.list(workspaceId) + console.log('found', list.length) + let removed = 0 + for (const obj of list) { + if (obj.lastModified < from) continue + if (obj.name.includes('%size%')) { + await minio.remove(workspaceId, [obj.name]) + removed++ + if (removed % 100 === 0) { + console.log('removed: ', removed) + } + } + } + console.log('FINISH, removed: ', removed) +} + export async function cleanRemovedTransactions (workspaceId: WorkspaceId, transactorUrl: string): Promise { const connection = (await connect(transactorUrl, workspaceId, undefined, { mode: 'backup' diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts index 26e39bec12..0628e1d04d 100644 --- a/dev/tool/src/index.ts +++ b/dev/tool/src/index.ts @@ -59,6 +59,7 @@ import { cleanRemovedTransactions, cleanWorkspace, fixCommentDoubleIdCreate, + fixMinioBW, fixSkills, optimizeModel } from './clean' @@ -493,6 +494,11 @@ export function devTool ( }) }) + program.command('fix-bw-workspace ').action(async (workspace: string) => { + const { minio } = prepareTools() + await fixMinioBW(getWorkspaceId(workspace, productId), minio) + }) + program .command('clean-removed-transactions ') .description('set user role')