fix(community): optimize leaderboard/community endpoint to prevent 30s timeout (#383)#385
Open
ismailkonvah wants to merge 1 commit intogenlayer-foundation:devfrom
Open
Conversation
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
This PR fixes issue #383 where the Community page (
Top Community Members) could fail withtimeout of 30000ms exceeded.Root Cause
The
/api/v1/leaderboard/community/endpoint serialized each user with fullUserSerializer, which is expensive and can trigger slow/N+1 query behavior as data grows.Changes
communityaction inbackend/leaderboard/views.py:UserSerializerusage with a lightweightvalues(...)projection for only required fields:id,name,address,profile_image_url,builder_points,validator_points,total_pointsSum) instead of Python loopslimitquery param (default200, clamped to1..1000) to control payload sizeWhy this fixes it
The endpoint now performs less work per row and returns a smaller payload, significantly reducing response time and lowering timeout risk on the Community page.
Issue
Closes #383
Testing
python -m py_compile backend/leaderboard/views.pypassed/communityTop Community Membersloads without timeout?limit=50returns bounded results