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()}
|
platform_map = {p.id: p for p in Platform.objects.all()}
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
|
root_assets_count = 0
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
platform = platform_map.get(asset.platform_id)
|
platform = platform_map.get(asset.platform_id)
|
||||||
if not platform:
|
if not platform:
|
||||||
continue
|
continue
|
||||||
pid = node_key or get_pid(asset, platform)
|
pid = node_key or get_pid(asset, platform)
|
||||||
if not pid or pid.isdigit():
|
if not pid:
|
||||||
continue
|
continue
|
||||||
|
# 根节点最多显示 1000 个资产
|
||||||
|
if pid.isdigit():
|
||||||
|
if root_assets_count > 1000:
|
||||||
|
continue
|
||||||
|
root_assets_count += 1
|
||||||
data.append({
|
data.append({
|
||||||
'id': str(asset.id),
|
'id': str(asset.id),
|
||||||
'name': asset.name,
|
'name': asset.name,
|
||||||
|
|
|
@ -196,10 +196,11 @@ class AssetPermissionListSerializer(AssetPermissionSerializer):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_eager_loading(cls, queryset):
|
def setup_eager_loading(cls, queryset):
|
||||||
"""Perform necessary eager loading of data."""
|
"""Perform necessary eager loading of data."""
|
||||||
queryset = queryset.annotate(
|
queryset = queryset \
|
||||||
users_amount=Count("users"),
|
.prefetch_related('labels', 'labels__label') \
|
||||||
user_groups_amount=Count("user_groups"),
|
.annotate(users_amount=Count("users"),
|
||||||
assets_amount=Count("assets"),
|
user_groups_amount=Count("user_groups"),
|
||||||
nodes_amount=Count("nodes"),
|
assets_amount=Count("assets"),
|
||||||
)
|
nodes_amount=Count("nodes"),
|
||||||
|
)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
Loading…
Reference in New Issue