From ee757e261dae0b0619ccbdfdd876a9e804c8aec8 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 16 Mar 2022 16:31:06 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rbac/api/rolebinding.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/rbac/api/rolebinding.py b/apps/rbac/api/rolebinding.py index 0dd431220..f7ad47351 100644 --- a/apps/rbac/api/rolebinding.py +++ b/apps/rbac/api/rolebinding.py @@ -8,7 +8,10 @@ from common.exceptions import JMSException from .. import serializers from ..models import RoleBinding, SystemRoleBinding, OrgRoleBinding -__all__ = ['RoleBindingViewSet', 'SystemRoleBindingViewSet', 'OrgRoleBindingViewSet'] +__all__ = [ + 'RoleBindingViewSet', 'SystemRoleBindingViewSet', + 'OrgRoleBindingViewSet' +] class RoleBindingViewSet(OrgBulkModelViewSet): @@ -22,9 +25,8 @@ class RoleBindingViewSet(OrgBulkModelViewSet): 'user__name', 'user__username', 'role__name' ] - @staticmethod - def annotate_queryset(queryset): - queryset = queryset \ + def get_queryset(self): + queryset = self._get_queryset()\ .prefetch_related('user', 'role', 'org') \ .annotate( user_display=Concat( @@ -35,10 +37,8 @@ class RoleBindingViewSet(OrgBulkModelViewSet): ) return queryset - def get_queryset(self): - queryset = super().get_queryset() - queryset = self.annotate_queryset(queryset) - return queryset + def _get_queryset(self): + return super().get_queryset() class SystemRoleBindingViewSet(RoleBindingViewSet): @@ -57,10 +57,8 @@ class SystemRoleBindingViewSet(RoleBindingViewSet): class OrgRoleBindingViewSet(RoleBindingViewSet): serializer_class = serializers.OrgRoleBindingSerializer - def get_queryset(self): - queryset = OrgRoleBinding.objects.root_all() - queryset = self.annotate_queryset(queryset) - return queryset + def _get_queryset(self): + return OrgRoleBinding.objects.root_all() def perform_bulk_create(self, serializer): validated_data = serializer.validated_data