mirror of https://github.com/jumpserver/jumpserver
perf: 兼用处理一下 tree
parent
df655f304a
commit
2b15fc5e8b
|
@ -81,13 +81,19 @@ class SerializeToTreeNodeMixin:
|
|||
platform_map = {p.id: p for p in Platform.objects.all()}
|
||||
|
||||
data = []
|
||||
root_assets_count = 0
|
||||
for asset in assets:
|
||||
platform = platform_map.get(asset.platform_id)
|
||||
if not platform:
|
||||
continue
|
||||
pid = node_key or get_pid(asset, platform)
|
||||
if not pid or pid.isdigit():
|
||||
if not pid:
|
||||
continue
|
||||
# 根节点最多显示 1000 个资产
|
||||
if pid.isdigit():
|
||||
if root_assets_count > 1000:
|
||||
continue
|
||||
root_assets_count += 1
|
||||
data.append({
|
||||
'id': str(asset.id),
|
||||
'name': asset.name,
|
||||
|
|
|
@ -196,10 +196,11 @@ class AssetPermissionListSerializer(AssetPermissionSerializer):
|
|||
@classmethod
|
||||
def setup_eager_loading(cls, queryset):
|
||||
"""Perform necessary eager loading of data."""
|
||||
queryset = queryset.annotate(
|
||||
users_amount=Count("users"),
|
||||
user_groups_amount=Count("user_groups"),
|
||||
assets_amount=Count("assets"),
|
||||
nodes_amount=Count("nodes"),
|
||||
)
|
||||
queryset = queryset \
|
||||
.prefetch_related('labels', 'labels__label') \
|
||||
.annotate(users_amount=Count("users"),
|
||||
user_groups_amount=Count("user_groups"),
|
||||
assets_amount=Count("assets"),
|
||||
nodes_amount=Count("nodes"),
|
||||
)
|
||||
return queryset
|
||||
|
|
Loading…
Reference in New Issue