mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
[Opt] Optimize query performance
This commit is contained in:
parent
7864fd4b59
commit
a0fee499dd
@ -392,11 +392,11 @@ class UserRankAPI(APIView):
|
||||
data = self.paginate_data(request, profiles, RankInfoSerializer)
|
||||
for i in range(0, len(data["results"])):
|
||||
try:
|
||||
user = User.objects.get(username=data["results"][i]["user"]["username"], is_disabled=False)
|
||||
user = User.objects.get(id=data["results"][i]["user"]["id"], is_disabled=False)
|
||||
userprofile = UserProfileSerializer(user.userprofile, show_real_name=False).data
|
||||
data["results"][i].update({"grade": userprofile["grade"], "title": userprofile["user"]["title"], "title_color": userprofile["user"]["title_color"]})
|
||||
except Exception:
|
||||
pass
|
||||
data["results"][i].update({"grade": 0, "title": None, "title_color": None})
|
||||
return self.success(data)
|
||||
|
||||
|
||||
|
||||
@ -192,9 +192,9 @@ class ContestRankAPI(APIView):
|
||||
page_qs["results"] = serializer(page_qs["results"], many=True, is_contest_admin=is_contest_admin).data
|
||||
for i in range(0, len(page_qs["results"])):
|
||||
try:
|
||||
user = User.objects.get(username=page_qs["results"][i]["user"]["username"], is_disabled=False)
|
||||
user = User.objects.get(id=page_qs["results"][i]["user"]["id"], is_disabled=False)
|
||||
userprofile = UserProfileSerializer(user.userprofile, show_real_name=True).data
|
||||
page_qs["results"][i].update({"grade": userprofile["grade"], "title": userprofile["user"]["title"], "title_color": userprofile["user"]["title_color"]})
|
||||
except Exception:
|
||||
pass
|
||||
page_qs["results"][i].update({"grade": 0, "title": None, "title_color": None})
|
||||
return self.success(page_qs)
|
||||
|
||||
@ -182,11 +182,11 @@ class ForumReplyAPI(APIView):
|
||||
data = ForumReplySerializer(forumreply).data
|
||||
|
||||
try:
|
||||
user = User.objects.get(username=data["author"]["username"], is_disabled=False)
|
||||
user = User.objects.get(id=data["author"]["id"], is_disabled=False)
|
||||
userprofile = UserProfileSerializer(user.userprofile, show_real_name=False).data
|
||||
data["author"].update({"grade": userprofile["grade"], "title": userprofile["user"]["title"], "title_color": userprofile["user"]["title_color"]})
|
||||
except Exception:
|
||||
pass
|
||||
data["author"].update({"grade": 0, "title": None, "title_color": None})
|
||||
|
||||
forumpost = ForumPostSerializer(ForumPost.objects.select_related("author").get(id=data["fa_id"])).data
|
||||
author = User.objects.get(username=forumpost["author"]["username"], is_disabled=False)
|
||||
@ -221,11 +221,11 @@ class ForumReplyAPI(APIView):
|
||||
data = self.paginate_data(request, forumreplys, ForumReplySerializer)
|
||||
for i in range(0, len(data["results"])):
|
||||
try:
|
||||
user = User.objects.get(username=data["results"][i]["author"]["username"], is_disabled=False)
|
||||
user = User.objects.get(id=data["results"][i]["author"]["id"], is_disabled=False)
|
||||
userprofile = UserProfileSerializer(user.userprofile, show_real_name=False).data
|
||||
data["results"][i]["author"].update({"grade": userprofile["grade"], "title": userprofile["user"]["title"], "title_color": userprofile["user"]["title_color"]})
|
||||
except Exception:
|
||||
pass
|
||||
data["results"][i]["author"].update({"grade": 0, "title": None, "title_color": None})
|
||||
return self.success(data)
|
||||
|
||||
@login_required
|
||||
|
||||
@ -156,11 +156,11 @@ class SubmissionListAPI(APIView):
|
||||
data["results"] = SubmissionListSerializer(data["results"], many=True, user=request.user).data
|
||||
for i in range(0, len(data["results"])):
|
||||
try:
|
||||
user = User.objects.get(username=data["results"][i]["username"], is_disabled=False)
|
||||
user = User.objects.get(id=data["results"][i]["user_id"], is_disabled=False)
|
||||
userprofile = UserProfileSerializer(user.userprofile, show_real_name=False).data
|
||||
data["results"][i].update({"grade": userprofile["grade"], "title": userprofile["user"]["title"], "title_color": userprofile["user"]["title_color"]})
|
||||
except Exception:
|
||||
pass
|
||||
data["results"][i].update({"grade": 0, "title": None, "title_color": None})
|
||||
return self.success(data)
|
||||
|
||||
|
||||
@ -203,11 +203,11 @@ class ContestSubmissionListAPI(APIView):
|
||||
data["results"] = SubmissionListSerializer(data["results"], many=True, user=request.user).data
|
||||
for i in range(0, len(data["results"])):
|
||||
try:
|
||||
user = User.objects.get(username=data["results"][i]["username"], is_disabled=False)
|
||||
user = User.objects.get(id=data["results"][i]["user_id"], is_disabled=False)
|
||||
userprofile = UserProfileSerializer(user.userprofile, show_real_name=True).data
|
||||
data["results"][i].update({"grade": userprofile["grade"], "title": userprofile["user"]["title"], "title_color": userprofile["user"]["title_color"]})
|
||||
except Exception:
|
||||
pass
|
||||
data["results"][i].update({"grade": 0, "title": None, "title_color": None})
|
||||
return self.success(data)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user