From 2f523dd29fabb6fb79b45e5e988a92f67ea5c05f Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 26 Dec 2024 17:39:13 +0800 Subject: [PATCH 1/2] optimize: add friendly logs --- api/services/plugin/plugin_migration.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/services/plugin/plugin_migration.py b/api/services/plugin/plugin_migration.py index eb885d4a31..145c66d07f 100644 --- a/api/services/plugin/plugin_migration.py +++ b/api/services/plugin/plugin_migration.py @@ -30,6 +30,11 @@ class PluginMigration: started_at = datetime.datetime(2023, 4, 3, 8, 59, 24) current_time = started_at + with Session(db.engine) as session: + total_tenant_count = session.query(Tenant.id).count() + + handled_tenant_count = 0 + while current_time < ended_at: # Initial interval of 1 day, will be dynamically adjusted based on tenant count interval = datetime.timedelta(days=1) @@ -91,6 +96,15 @@ class PluginMigration: plugins = cls.extract_installed_plugin_ids(tenant_id) print(plugins) + handled_tenant_count += len(tenants) + + click.echo( + click.style( + f"Processed {handled_tenant_count} tenants ({(handled_tenant_count/total_tenant_count)*100:.1f}%), {handled_tenant_count}/{total_tenant_count}", + fg="green", + ) + ) + current_time = batch_end @classmethod From 0249f15609ed62251b8d67374d0c7d1b6c6d2bb9 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 26 Dec 2024 17:39:21 +0800 Subject: [PATCH 2/2] fix: linter --- api/services/plugin/plugin_migration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/services/plugin/plugin_migration.py b/api/services/plugin/plugin_migration.py index 145c66d07f..d68414219c 100644 --- a/api/services/plugin/plugin_migration.py +++ b/api/services/plugin/plugin_migration.py @@ -100,7 +100,9 @@ class PluginMigration: click.echo( click.style( - f"Processed {handled_tenant_count} tenants ({(handled_tenant_count/total_tenant_count)*100:.1f}%), {handled_tenant_count}/{total_tenant_count}", + f"Processed {handled_tenant_count} tenants " + f"({(handled_tenant_count / total_tenant_count) * 100:.1f}%), " + f"{handled_tenant_count}/{total_tenant_count}", fg="green", ) )