mirror of https://github.com/jumpserver/jumpserver
perf: 接口sql优化 /api/v1/accounts/account-templates/su-from-account-templates/
parent
bccf3a0340
commit
4e9012cc07
|
@ -49,8 +49,7 @@ class AccountTemplateViewSet(OrgBulkModelViewSet):
|
||||||
@action(methods=['get'], detail=False, url_path='su-from-account-templates')
|
@action(methods=['get'], detail=False, url_path='su-from-account-templates')
|
||||||
def su_from_account_templates(self, request, *args, **kwargs):
|
def su_from_account_templates(self, request, *args, **kwargs):
|
||||||
pk = request.query_params.get('template_id')
|
pk = request.query_params.get('template_id')
|
||||||
template = AccountTemplate.objects.filter(pk=pk).first()
|
templates = AccountTemplate.get_su_from_account_templates(pk)
|
||||||
templates = AccountTemplate.get_su_from_account_templates(template)
|
|
||||||
templates = self.filter_queryset(templates)
|
templates = self.filter_queryset(templates)
|
||||||
serializer = self.get_serializer(templates, many=True)
|
serializer = self.get_serializer(templates, many=True)
|
||||||
return Response(data=serializer.data)
|
return Response(data=serializer.data)
|
||||||
|
|
|
@ -124,10 +124,10 @@ class AccountTemplate(BaseAccount):
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_su_from_account_templates(cls, instance=None):
|
def get_su_from_account_templates(cls, pk=None):
|
||||||
if not instance:
|
if pk is None:
|
||||||
return cls.objects.all()
|
return cls.objects.all()
|
||||||
return cls.objects.exclude(Q(id=instance.id) | Q(su_from=instance))
|
return cls.objects.exclude(Q(id=pk) | Q(_id=pk))
|
||||||
|
|
||||||
def get_su_from_account(self, asset):
|
def get_su_from_account(self, asset):
|
||||||
su_from = self.su_from
|
su_from = self.su_from
|
||||||
|
|
Loading…
Reference in New Issue