Skip to content

Commit 2ff708e

Browse files
committed
Reuse preloaded participation and show N/A scores
Avoid a duplicate DB query by reusing a participation object that ContestHandler may have preloaded for sidebar scores; only call _load_participation_for_scores when necessary. Compute task scores conditionally as before. UI fixes: display "N/A" for undefined task scores in the contest sidebar, add CSS for the undefined badge state, and ensure task submission badges remove the undefined class and are shown after updating the score.
1 parent 7271662 commit 2ff708e

4 files changed

Lines changed: 25 additions & 12 deletions

File tree

cms/server/contest/handlers/main.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,26 @@ def render_params(self):
8282
ret = super().render_params()
8383

8484
if self.current_user is not None:
85-
participation = self._load_participation_for_scores(self.current_user)
86-
if participation is None:
87-
return ret
85+
participation = ret["participation"]
8886

89-
self.contest = participation.contest
90-
# Ensure the template sees this fully-loaded version.
91-
ret["contest"] = self.contest
92-
ret["participation"] = participation
93-
ret["user"] = participation.user
94-
95-
# Compute public scores for all tasks only if they will be shown
87+
# ContestHandler may have already loaded a fully-joined participation
88+
# while computing sidebar scores. Reuse it to avoid a duplicate query.
89+
already_preloaded_for_scores = "sidebar_task_scores" in ret
9690
if self.contest.show_task_scores_in_overview:
91+
if not already_preloaded_for_scores:
92+
loaded_participation = self._load_participation_for_scores(
93+
participation
94+
)
95+
if loaded_participation is None:
96+
return ret
97+
participation = loaded_participation
98+
99+
self.contest = participation.contest
100+
# Ensure the template sees this fully-loaded version.
101+
ret["contest"] = self.contest
102+
ret["participation"] = participation
103+
ret["user"] = participation.user
104+
97105
ret["task_scores"] = self._compute_task_scores(
98106
participation,
99107
actual_phase=ret["actual_phase"],

cms/server/contest/static/cws_style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ td.token_rules p:last-child {
473473
color: #333;
474474
text-transform: none;
475475
}
476+
.nav-list .nav-header .task_score_badge.undefined {
477+
color: #888;
478+
background-color: transparent;
479+
}
476480
/*** Submit a solution */
477481

478482
#submit_solution {

cms/server/contest/templates/contest.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ <h3 id="countdown_box">
187187
{{ sidebar_task_scores[t_iter.id][2] }}
188188
</span>
189189
{% else %}
190-
<span class="task_score_badge task_score undefined"></span>
190+
<span class="task_score_badge task_score undefined">{% trans %}N/A{% endtrans %}</span>
191191
{% endif %}
192192
{% endif %}
193193
</li>

cms/server/contest/templates/task_submissions.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@
132132
return;
133133
}
134134

135-
badge.removeClass('score_0 score_0_100 score_100');
135+
badge.removeClass('undefined score_0 score_0_100 score_100');
136136
badge.addClass(get_score_class(task_score, max_score));
137137
badge.text(task_score_message);
138+
badge.show();
138139
};
139140

140141
update_scores = function (submission_id, data) {

0 commit comments

Comments
 (0)