Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): 集群列表查询优化 #7781 #7783

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dbm-ui/backend/db_services/dbbase/resources/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}

# 获取集群操作记录的映射关系
Expand All @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/ticket/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading