Skip to content

Commit

Permalink
perf: /contest/预先查询question__choice_set
Browse files Browse the repository at this point in the history
这样初次访问`/contest/`时可以减少19次SQL(31 → 12)。
  • Loading branch information
YDX-2147483647 committed Aug 25, 2024
1 parent 8f654dd commit 389c0e5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion contest/quiz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def contest(request: AuthenticatedHttpRequest) -> HttpResponse:
{
"draft_response": draft_response,
# 为渲染模板预先从数据库查询相关内容
"answer_set": draft_response.answer_set.select_related("question", "choice"),
"answer_set": draft_response.answer_set.select_related("question").prefetch_related('question__choice_set'),
"constants": constants,
},
)
Expand Down

0 comments on commit 389c0e5

Please sign in to comment.