fix(be): fix contest leaderboard ranking malfunction#3419
fix(be): fix contest leaderboard ranking malfunction#3419
Conversation
|
✅ Syncing Preview App Succeeded Application: |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the contest leaderboard calculation logic in ContestService, introducing custom sorting and ranking based on solved problems and penalties, and adds new seeding data for contestId7 to test these changes. The review highlights a performance regression in ContestService due to sequential database queries that should be parallelized using Promise.all. Additionally, the new ranking logic in ContestService does not correctly handle ties, and a related comment is misleading. In prisma/seed.ts, the newly created contest7Records are not included in the function's return value, and there's a typo in a comment describing the number of solved problems for a test user.
…& penalty and add seed data
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the leaderboard calculation logic in ContestService, moving sorting and ranking from the database query to application memory. It introduces manual calculation of scores, penalties, and solved problem counts, and implements a ranking algorithm to handle ties. Additionally, seed data for testing these changes was added. The review feedback suggests enhancing the sorting and ranking logic by incorporating totalScore and lastAcceptedTime as tie-breakers to ensure fairness and accuracy.
…2-modify-contest-statistics-leaderboard
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the contest leaderboard logic to calculate rankings based on the number of solved problems, total penalty, and the last accepted time. It also introduces new seed data for testing these ranking criteria. Feedback highlights a logic mismatch between the sorting and ranking assignment steps regarding totalScore, potential inconsistencies with other statistics methods in the service, and missing finishTime data in the new test seeds.
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect contest leaderboard ranking by changing how leaderboard entries are aggregated and ranked (with additional seed data to reproduce/test the issue).
Changes:
- Reworked
/contest/:id/leaderboardranking to derive solved/penalty from per-problem records and sort accordingly. - Added seed data for contest 7 to reproduce leaderboard ranking scenarios.
- Updated the Bruno collection request to call contest 7’s leaderboard.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| collection/client/Contest/Get Leaderboard/Succeed.bru | Points the sample leaderboard request to contest id 7 for testing. |
| apps/backend/prisma/seed.ts | Adds contest 7 seed records intended for leaderboard ranking validation. |
| apps/backend/apps/client/src/contest/contest.service.ts | Recomputes leaderboard totals and implements in-memory sorting + rank assignment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <copilot@github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the contest leaderboard logic to include lastAcceptedTime as a tie-breaking criterion and transitions to manual rank calculation within the service. It also adds comprehensive seed data to test these ranking scenarios and updates the associated API test collection. Feedback suggests centralizing the new sorting logic within the calculateRanks helper to ensure consistency across different statistics views and updating the API documentation in the .bru file to reflect the new response fields.
| leaderboard.sort((a, b) => { | ||
| //1순위: 맞춘 문제 개수 많을수록 상위 | ||
| if (b.solvedProblemCount !== a.solvedProblemCount) { | ||
| return b.solvedProblemCount - a.solvedProblemCount | ||
| } | ||
|
|
||
| //2순위: 패널티 작을수록 상위 | ||
| if (a.totalPenalty !== b.totalPenalty) { | ||
| return a.totalPenalty - b.totalPenalty | ||
| } | ||
|
|
||
| //3순위: 맞춘문제, 패널티 모두 동점일 경우 마지막 정답 제출시간 빠를수록 상위 | ||
| const timeA = a.lastAcceptedTime?.getTime() ?? Number.MAX_SAFE_INTEGER | ||
| const timeB = b.lastAcceptedTime?.getTime() ?? Number.MAX_SAFE_INTEGER | ||
| return timeA - timeB | ||
| }) |
There was a problem hiding this comment.
The sorting logic for the leaderboard has been updated to include lastAcceptedTime as a third-tier criterion. However, this logic is now inlined here, while other methods like getContestUsersStatistics and getContestUserStatistics still rely on the calculateRanks helper method which does not yet account for lastAcceptedTime. This will result in inconsistent rankings across different views (e.g., the leaderboard vs. the statistics page). It is recommended to update the calculateRanks method to include all three criteria and use it consistently throughout the service to maintain a single source of truth for ranking logic.
|
|
||
| params:path { | ||
| id: 1 | ||
| id: 7 |
There was a problem hiding this comment.
While updating the contest ID for the test, the documentation for the response format (lines 37-79) was not updated to reflect the new fields added to the leaderboard records (solvedProblemCount, lastAcceptedTime). Please update the documentation to ensure it remains accurate and helpful for API consumers.
Description
Contest 리더보드 순위 오류 수정
변경사항
테스트
contest 7 기준
contestProblem 문제는 problemId 5,6,7,8 총 4개 (점수 각각 50, 60, 70, 80)
user02~user08 까지 7명의 user 대회 기록 생성 (seed.ts)
Before submitting the PR, please make sure you do the following
fixes #123).