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)