From 48a16d91b5d17b7d984e8df04ad642a7e2dc1b16 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 26 May 2026 21:46:56 -0600 Subject: [PATCH] refactor: replace sync_to_async aggregate with aaggregate in problem views --- problem/views/oj.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/problem/views/oj.py b/problem/views/oj.py index 8fc4c96..cfa4896 100644 --- a/problem/views/oj.py +++ b/problem/views/oj.py @@ -1,6 +1,5 @@ import random -from asgiref.sync import sync_to_async from django.db.models import BooleanField, Case, Count, Q, Value, When from django.db.models.functions import ExtractYear from django.utils import timezone @@ -203,14 +202,11 @@ class ProblemSolvedPeopleCount(AsyncAPIView): years_ago = now.replace(year=now.year - 2, hour=0, minute=0, second=0, microsecond=0) total_count = await User.objects.filter(is_disabled=False, last_login__gte=years_ago).acount() accepted_count = ( - await sync_to_async( - Submission.objects.filter( - problem_id=problem_id, - result__in=[JudgeStatus.ACCEPTED, JudgeStatus.AST_CHECK_FAILED], - create_time__gte=years_ago, - ).aggregate, - thread_sensitive=True, - )(user_count=Count("user_id", distinct=True)) + await Submission.objects.filter( + problem_id=problem_id, + result__in=[JudgeStatus.ACCEPTED, JudgeStatus.AST_CHECK_FAILED], + create_time__gte=years_ago, + ).aaggregate(user_count=Count("user_id", distinct=True)) )["user_count"] if total_count and accepted_count < total_count: rate = "%.2f" % ((total_count - accepted_count) / total_count * 100)