From 065f7168337ad077fae468dae516f0ce8b89da24 Mon Sep 17 00:00:00 2001 From: durant <826035498@qq.com> Date: Thu, 7 Nov 2024 18:00:47 +0800 Subject: [PATCH] =?UTF-8?q?perf(backend):=20=E4=BC=98=E5=8C=96=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E5=90=AF=E5=8A=A8=E9=80=9F=E5=BA=A6=20#7809?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_meta/models/db_module.py | 27 +++++++++------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/dbm-ui/backend/db_meta/models/db_module.py b/dbm-ui/backend/db_meta/models/db_module.py index f614abb320..77eaf1a40e 100644 --- a/dbm-ui/backend/db_meta/models/db_module.py +++ b/dbm-ui/backend/db_meta/models/db_module.py @@ -63,27 +63,22 @@ def get_choices_with_filter(cls, cluster_type=None): if cluster_type: q = Q(cluster_type=cluster_type) - # logger.info("get db module choices with filter: {}".format(q)) - db_module_choices = [] + appcache_dict = AppCache.get_appcache(key="appcache_dict") for dm in cls.objects.filter(q).all(): - - try: - appcache_dict = AppCache.get_appcache(key="appcache_dict") - appcache = appcache_dict.get(str(dm.bk_biz_id)) - db_module_choices.append( - ( - dm.db_module_id, - f"[{dm.db_module_id}]-" - f"[{dm.cluster_type}]-[app:{appcache['db_app_abbr']}]-" - f"{dm.db_module_name}", - ) + appcache = appcache_dict.get(str(dm.bk_biz_id)) + db_module_choices.append( + ( + dm.db_module_id, + f"[{dm.db_module_id}]-" + f"[{dm.cluster_type}]-[app:{appcache['db_app_abbr']}]-" + f"{dm.db_module_name}", ) - except AppCache.DoesNotExist: - continue + ) - except Exception: # pylint: disable=broad-except + except Exception as err: # pylint: disable=broad-except # 忽略出现的异常,此时可能因为表未初始化 + logger.exception("DBModule get_choices_with_filter error, {}".format(err)) db_module_choices = [] return db_module_choices