From 21ba32e8a76736e10494da71c74b687a6d7d5340 Mon Sep 17 00:00:00 2001 From: ycggyao Date: Mon, 11 Nov 2024 17:00:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E9=9B=86=E7=BE=A4=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96=20#7781=20#=20Rev?= =?UTF-8?q?iewed,=20transaction=20id:=2023476?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_services/dbbase/resources/query.py | 11 ++++++++--- dbm-ui/backend/ticket/models/ticket.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dbm-ui/backend/db_services/dbbase/resources/query.py b/dbm-ui/backend/db_services/dbbase/resources/query.py index 6c39761d00..3d5cdf4712 100644 --- a/dbm-ui/backend/db_services/dbbase/resources/query.py +++ b/dbm-ui/backend/db_services/dbbase/resources/query.py @@ -506,8 +506,10 @@ def _filter_cluster_hook( # 获取DB模块的映射信息 db_module_names_map = { - module.db_module_id: module.db_module_name - for module in DBModule.objects.filter(bk_biz_id=bk_biz_id, cluster_type__in=cls.cluster_types) + module["db_module_id"]: module["db_module_name"] + for module in DBModule.objects.filter(bk_biz_id=bk_biz_id, cluster_type__in=cls.cluster_types).values( + "db_module_id", "db_module_name" + ) } # 获取集群操作记录的映射关系 @@ -519,6 +521,9 @@ def _filter_cluster_hook( # 将集群的查询结果序列化为集群字典信息 clusters: List[Dict[str, Any]] = [] + # 获取集群统计信息,只需要获取一次 + cluster_stats_map = Cluster.get_cluster_stats(bk_biz_id, cls.cluster_types) + for cluster in cluster_list: cluster_info = cls._to_cluster_representation( cluster=cluster, @@ -531,7 +536,7 @@ def _filter_cluster_hook( cluster_operate_records_map=cluster_operate_records_map, cloud_info=cloud_info, biz_info=biz_info, - cluster_stats_map=Cluster.get_cluster_stats(bk_biz_id, cls.cluster_types), + cluster_stats_map=cluster_stats_map, **kwargs, ) clusters.append(cluster_info) diff --git a/dbm-ui/backend/ticket/models/ticket.py b/dbm-ui/backend/ticket/models/ticket.py index cea46db296..c9dac3d7e3 100644 --- a/dbm-ui/backend/ticket/models/ticket.py +++ b/dbm-ui/backend/ticket/models/ticket.py @@ -348,7 +348,7 @@ def summary(self): @classmethod def get_cluster_records_map(cls, cluster_ids: List[int]): """获取集群与操作记录之间的映射关系""" - records = cls.objects.prefetch_related("ticket").filter( + records = cls.objects.select_related("ticket", "flow").filter( cluster_id__in=cluster_ids, ticket__status=TicketFlowStatus.RUNNING ) cluster_operate_records_map: Dict[int, List] = defaultdict(list)