Backend: Optimize leaderboard query with two-stage fetch to reduce payload#5087
Open
akanshajain231999 wants to merge 4 commits into
Open
Backend: Optimize leaderboard query with two-stage fetch to reduce payload#5087akanshajain231999 wants to merge 4 commits into
akanshajain231999 wants to merge 4 commits into
Conversation
Refactor calculate_distinct_sorted_leaderboard_data to avoid transferring heavy JSON columns (result, error, submission_metadata) for rows that get discarded by per-team deduplication. Stage 1 fetches a lightweight projection used for sort + dedup; stage 2 re-fetches full rows only for the retained IDs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Reformat unique_team_ids set comprehension to satisfy black. - Add "id" key to mocked test_data in five TestReorderSubmissionsComparator cases so stage-2 fetch (filter id__in=...) does not KeyError. - Switch test_multiple_banned_participants_in_team to use _create_mock_leaderboard_chain helper for the stage-2 chain. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5087 +/- ##
==========================================
- Coverage 91.72% 91.69% -0.03%
==========================================
Files 96 96
Lines 8155 8168 +13
==========================================
+ Hits 7480 7490 +10
- Misses 675 678 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
calculate_distinct_sorted_leaderboard_datainapps/jobs/utils.pyinto a two-stage query to avoid transferring heavy JSON columns (result,error,submission_metadata) for rows discarded by per-team deduplication.submission__execution_timeannotation) only for the retained IDs, preserving stage-1 order.tests/unit/jobs/test_utils.pyto includeidon test rows and extend the mock query chain for the stage-2 fetch.Test plan
pytest tests/unit/jobs/test_utils.pypasses locally🤖 Generated with Claude Code