mirror of https://github.com/jumpserver/jumpserver
Merge pull request #10711 from jumpserver/pr@dev@perf_json_field_select
perf: 优化查询 aclspull/10715/head
commit
29ebdb03e7
|
@ -110,11 +110,11 @@ class UserAssetAccountBaseACL(OrgModelMixin, UserBaseACL):
|
|||
@classmethod
|
||||
def filter_queryset(cls, user=None, asset=None, account=None, account_username=None, **kwargs):
|
||||
queryset = cls.objects.all()
|
||||
org_id = None
|
||||
|
||||
if user:
|
||||
q = cls.users.get_filter_q(user)
|
||||
queryset = queryset.filter(q)
|
||||
|
||||
if asset:
|
||||
org_id = asset.org_id
|
||||
with tmp_to_org(org_id):
|
||||
|
@ -127,8 +127,6 @@ class UserAssetAccountBaseACL(OrgModelMixin, UserBaseACL):
|
|||
models.Q(accounts__contains='*') | \
|
||||
models.Q(accounts__contains='@ALL')
|
||||
queryset = queryset.filter(q)
|
||||
if org_id:
|
||||
kwargs['org_id'] = org_id
|
||||
if kwargs:
|
||||
queryset = queryset.filter(**kwargs)
|
||||
return queryset.valid().distinct()
|
||||
|
|
|
@ -90,8 +90,10 @@ def create_app_nodes(apps, org_id):
|
|||
next_value = max([int(k[1]) for k in node_key_split]) + 1
|
||||
parent_key = node_key_split[0][0]
|
||||
else:
|
||||
root_node = node_model.objects.filter(org_id=org_id)\
|
||||
.filter(parent_key='', key__regex=r'^[0-9]+$').exclude(key__startswith='-').first()
|
||||
root_node = node_model.objects.filter(org_id=org_id) \
|
||||
.filter(parent_key='', key__regex=r'^[0-9]+$') \
|
||||
.exclude(key__startswith='-') \
|
||||
.first()
|
||||
if not root_node:
|
||||
return
|
||||
parent_key = root_node.key
|
||||
|
|
|
@ -295,7 +295,13 @@ class RelatedManager:
|
|||
self.instance.__dict__[self.field.name] = value
|
||||
|
||||
@classmethod
|
||||
def get_filter_q(cls, value, to_model):
|
||||
def _get_filter_q(cls, value, to_model):
|
||||
"""
|
||||
这个是 instance 去查找 to_model 的 queryset 的 Q
|
||||
:param value:
|
||||
:param to_model:
|
||||
:return:
|
||||
"""
|
||||
if not value or not isinstance(value, dict):
|
||||
return Q()
|
||||
|
||||
|
@ -314,7 +320,7 @@ class RelatedManager:
|
|||
queryset = to_model.get_queryset()
|
||||
else:
|
||||
queryset = to_model.objects.all()
|
||||
q = cls.get_filter_q(value, to_model)
|
||||
q = cls._get_filter_q(value, to_model)
|
||||
return queryset.filter(q).distinct()
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue