perf(perms): 优化根据资产获取授权的系统用户

pull/4901/head
xinwen 2020-10-30 12:22:57 +08:00 committed by Jiangjie.Bai
parent f6c24f809c
commit c90b9d70dc
1 changed files with 4 additions and 1 deletions

View File

@ -11,16 +11,19 @@ logger = get_logger(__file__)
def get_asset_system_users_id_with_actions(asset_perm_queryset: BasePermissionQuerySet, asset: Asset):
asset_perms_id = set(asset_perm_queryset.values_list('id', flat=True))
nodes = asset.get_nodes()
node_keys = set()
for node in nodes:
ancestor_keys = node.get_ancestor_keys(with_self=True)
node_keys.update(ancestor_keys)
queryset = asset_perm_queryset.filter(
queryset = AssetPermission.objects.filter(id__in=asset_perms_id).filter(
Q(assets=asset) |
Q(nodes__key__in=node_keys)
)
asset_protocols = asset.protocols_as_dict.keys()
values = queryset.filter(
system_users__protocol__in=asset_protocols