perf: history account model queryset (#8588)

Co-authored-by: feng626 <1304903146@qq.com>
pull/8592/head
fit2bot 2 years ago committed by GitHub
parent f758414844
commit 4a3d7a8524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,7 +30,11 @@ class AccountHistoryViewSet(AccountViewSet):
http_method_names = ['get', 'options']
def get_queryset(self):
queryset = AuthBook.get_queryset(is_history_model=True)
queryset = self.model.objects.all() \
.annotate(ip=F('asset__ip')) \
.annotate(hostname=F('asset__hostname')) \
.annotate(platform=F('asset__platform__name')) \
.annotate(protocols=F('asset__protocols'))
return queryset

@ -125,9 +125,8 @@ class AuthBook(BaseUser, AbsConnectivity):
logger.debug('Update asset admin user: {} {}'.format(self.asset, self.systemuser))
@classmethod
def get_queryset(cls, is_history_model=False):
model = cls.history.model if is_history_model else cls
queryset = model.objects.all() \
def get_queryset(cls):
queryset = cls.objects.all() \
.annotate(ip=F('asset__ip')) \
.annotate(hostname=F('asset__hostname')) \
.annotate(platform=F('asset__platform__name')) \

Loading…
Cancel
Save