From e73324f8f6db9ee2fe218c11f135134f7f66057d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 10 Mar 2024 12:48:43 +0900 Subject: remove limit of the number of shown users in ranking --- services/app/src/App.php | 2 +- services/app/src/Repositories/AnswerRepository.php | 33 +++++++--------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/services/app/src/App.php b/services/app/src/App.php index ec64efd..cd7798f 100644 --- a/services/app/src/App.php +++ b/services/app/src/App.php @@ -261,7 +261,7 @@ final class App if ($quiz->isRankingHidden()) { $ranking = null; } else { - $ranking = $answerRepo->getRankingByBestScores($quiz->quiz_id, upto: 20); + $ranking = $answerRepo->getRankingByBestScores($quiz->quiz_id, upto: null); } return $this->render($request, $response, 'quiz_view.html.twig', [ diff --git a/services/app/src/Repositories/AnswerRepository.php b/services/app/src/Repositories/AnswerRepository.php index 7ea3d4f..6ccfb32 100644 --- a/services/app/src/Repositories/AnswerRepository.php +++ b/services/app/src/Repositories/AnswerRepository.php @@ -94,28 +94,10 @@ final class AnswerRepository } /** - * @param positive-int $upto + * @param ?positive-int $upto * @return Answer[] */ - public function getRanking(int $quiz_id, int $upto): array - { - $result = $this->conn - ->query() - ->select('answers') - ->leftJoin('users', 'answers.author_id = users.user_id') - ->fields([...self::ANSWER_FIELDS, ...self::ANSWER_JOIN_USER_FIELDS]) - ->where('quiz_id = :quiz_id AND execution_status = :execution_status') - ->orderBy([['code_size', 'ASC'], ['submitted_at', 'ASC']]) - ->limit($upto) - ->execute(['quiz_id' => $quiz_id, 'execution_status' => AggregatedExecutionStatus::OK->toInt()]); - return array_map($this->mapRawRowToAnswer(...), $result); - } - - /** - * @param positive-int $upto - * @return Answer[] - */ - public function getRankingByBestScores(int $quiz_id, int $upto): array + public function getRankingByBestScores(int $quiz_id, ?int $upto): array { $q = $this->conn ->query() @@ -128,7 +110,7 @@ final class AnswerRepository ]) ->where('quiz_id = :quiz_id AND execution_status = :execution_status'); - $result = $this->conn + $query = $this->conn ->query() ->select($q) ->fields([ @@ -137,8 +119,13 @@ final class AnswerRepository 'author_is_admin', ]) ->where('r = 1') - ->orderBy([['code_size', 'ASC'], ['submitted_at', 'ASC']]) - ->limit($upto) + ->orderBy([['code_size', 'ASC'], ['submitted_at', 'ASC']]); + + if ($upto !== null) { + $query = $query->limit($upto); + } + + $result = $query ->execute(['quiz_id' => $quiz_id, 'execution_status' => AggregatedExecutionStatus::OK->toInt()]); return array_map($this->mapRawRowToAnswer(...), $result); } -- cgit v1.2.3-70-g09d2