Skip to content

perf(leaderboard): reduce builder/community "view all" latency by skipping validator-only counts (#378)#386

Open
ismailkonvah wants to merge 1 commit intogenlayer-foundation:devfrom
ismailkonvah:fix/builders-viewall-performance-378
Open

perf(leaderboard): reduce builder/community "view all" latency by skipping validator-only counts (#378)#386
ismailkonvah wants to merge 1 commit intogenlayer-foundation:devfrom
ismailkonvah:fix/builders-viewall-performance-378

Conversation

@ismailkonvah
Copy link

Summary

This PR improves performance for "View All Builders" and other non-validator leaderboard views by removing unnecessary validator-wallet counting work from the request path.

Problem

Issue #378 reports slow loading in builder-focused "view all" flows.
The leaderboard endpoint was always adding validator wallet count annotations, and serializer fallback logic could still query validator wallets even for non-validator leaderboard rows.

Changes

1) Optimize queryset annotations by leaderboard type

In LeaderboardViewSet.get_queryset:

  • Moved type resolution earlier
  • Applied validator wallet annotations only when type is validator-related:
    • validator
    • validator-waitlist
    • validator-waitlist-graduation
  • Non-validator leaderboards (e.g. builder/community) now skip these expensive joins/counts.

2) Prevent serializer fallback queries on non-validator rows

In LeaderboardEntrySerializer.get_active_validators_count:

  • Early-return None when entry type is not validator-related
  • Keeps validator count behavior unchanged for validator leaderboards
  • Avoids extra DB queries during serialization for builder/community lists

Why this helps

Builder/community "view all" requests no longer perform validator-specific counting logic, reducing query complexity and serialization overhead.

Scope

  • No API contract changes for existing leaderboard fields
  • Validator leaderboards keep active validator count behavior
  • Non-validator leaderboards now avoid unnecessary count work

Issue

Closes #378

Validation

  • Static check passed:
    • python -m py_compile backend/leaderboard/views.py backend/leaderboard/serializers.py

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.

view all builders section loads slower than other tabs

2 participants