后台出题人

This commit is contained in:
2025-10-03 14:30:40 +08:00
parent ce2a4629da
commit 7835cf013a
2 changed files with 190 additions and 110 deletions

View File

@@ -192,15 +192,19 @@ class ProblemSolvedPeopleCount(APIView):
class ProblemAuthorAPI(APIView):
def get(self, request):
# 统计出题用户
cached_data = cache.get(CacheKey.problem_authors)
show_all = request.GET.get("all", "0") == "1"
cached_data = cache.get(
f"{CacheKey.problem_authors}{'_all' if show_all else '_only_visible'}"
)
if cached_data:
return self.success(cached_data)
problem_filter = {"contest_id__isnull": True, "created_by__is_disabled": False}
if not show_all:
problem_filter["visible"] = True
authors = (
Problem.objects.filter(
visible=True, contest_id__isnull=True, created_by__is_disabled=False
)
Problem.objects.filter(**problem_filter)
.values("created_by__username")
.annotate(problem_count=Count("id"))
.order_by("-problem_count")
@@ -213,5 +217,5 @@ class ProblemAuthorAPI(APIView):
for author in authors
]
cache.set(CacheKey.problem_authors, result, 3600)
cache.set(CacheKey.problem_authors, result, 7200)
return self.success(result)