From 892a56a88198f4c1fdd3ec407014fbe80346f84e Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 21 Oct 2022 22:18:10 +0800 Subject: [PATCH] fix(web/group/assignment): db query perf --- web/app/controllers/group_assignment.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/app/controllers/group_assignment.php b/web/app/controllers/group_assignment.php index ee72dc1..0964848 100644 --- a/web/app/controllers/group_assignment.php +++ b/web/app/controllers/group_assignment.php @@ -78,7 +78,13 @@ foreach ($problem_ids as $problem_id) { $cond = "submitter = '{$user['username']}' AND problem_id = $problem_id AND submit_time <= '$submission_end_time'"; - $submission = DB::selectFirst("SELECT id, score FROM submissions INNER JOIN (SELECT MAX(score) AS score FROM submissions WHERE $cond) AS max USING (score) WHERE $cond ORDER BY submit_time DESC"); + $max_score_query = DB::selectFirst("SELECT MAX(score) AS score FROM submissions WHERE $cond"); + if ($max_score_query) { + $max_score = $max_score_query['score']; + } else { + $max_score = 0; + } + $submission = DB::selectFirst("SELECT id, score FROM submissions WHERE $cond AND score = $max_score ORDER BY submit_time DESC LIMIT 1"); if ($submission) { $row['scores'][] = [