Skip to content

fix(community): optimize leaderboard/community endpoint to prevent 30s timeout (#383)#385

Open
ismailkonvah wants to merge 1 commit intogenlayer-foundation:devfrom
ismailkonvah:fix/community-timeout-383
Open

fix(community): optimize leaderboard/community endpoint to prevent 30s timeout (#383)#385
ismailkonvah wants to merge 1 commit intogenlayer-foundation:devfrom
ismailkonvah:fix/community-timeout-383

Conversation

@ismailkonvah
Copy link

Summary

This PR fixes issue #383 where the Community page (Top Community Members) could fail with timeout of 30000ms exceeded.

Root Cause

The /api/v1/leaderboard/community/ endpoint serialized each user with full UserSerializer, which is expensive and can trigger slow/N+1 query behavior as data grows.

Changes

  • Optimized community action in backend/leaderboard/views.py:
    • Replaced full UserSerializer usage with a lightweight values(...) projection for only required fields:
      • id, name, address, profile_image_url, builder_points, validator_points, total_points
    • Moved totals computation to DB aggregation (Sum) instead of Python loops
    • Added optional limit query param (default 200, clamped to 1..1000) to control payload size

Why 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

  • Static check: python -m py_compile backend/leaderboard/views.py passed
  • Manual verification recommended:
    1. Open /community
    2. Confirm Top Community Members loads without timeout
    3. (Optional) Verify ?limit=50 returns bounded results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Community page not loading – timeout error (low priority)

1 participant