From 36aa0d301bbe5d7373c85d9b7b27001cbd24f2e0 Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Wed, 17 May 2023 16:16:34 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20ops=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/api/job.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/ops/api/job.py b/apps/ops/api/job.py index ca76263a4..5d7012a8f 100644 --- a/apps/ops/api/job.py +++ b/apps/ops/api/job.py @@ -158,14 +158,17 @@ class UsernameHintsAPI(APIView): def post(self, request, **kwargs): node_ids = request.data.get('nodes', None) asset_ids = request.data.get('assets', []) + query = request.data.get('query', None) + assets = list(Asset.objects.filter(id__in=asset_ids).all()) assets = merge_nodes_and_assets(node_ids, assets, request.user) - top_accounts = Account.objects.exclude(username='root') \ + top_accounts = Account.objects \ .exclude(username__startswith='jms_') \ + .filter(username__icontains=query) \ .filter(asset__in=assets) \ .values('username') \ .annotate(total=Count('username')) \ - .order_by('total', 'username')[:10] + .order_by('total', '-username')[:10] return Response(data=top_accounts)