[BUG]: Leaderboard loads all users with no limit or pagination — scalability concern
Maintainers usually reply within 1 day
A pull request for this has already been merged.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start with GetLeaderboard in backend/controllers/leaderboard.go, focusing on the unbounded Find and the totalUsers calculation. Check how the handler builds and returns leaderboard data, then verify the result is capped while totalUsers still reflects the full collection. The issue suggests using CountDocuments for that total.
Written by the indexing model from the issue text.
Description
Bug Description
GetLeaderboard in backend/controllers/leaderboard.go fetches every user in the database with no limit or pagination:
findOptions := options.Find().SetSort(bson.D{{"rating", -1}})
cursor, err := collection.Find(c, bson.M{}, findOptions) // no .SetLimit()
...
var users []models.User
cursor.All(c, &users) // all users loaded into memory
It then builds the full debaters list from every user and returns it. As the user base grows, this loads the entire users collection into memory on every leaderboard request and returns an unbounded payload, with no way for the frontend to page through ranks.
A leaderboard typically needs only the top N (e.g. top 100), optionally paginated.
Note on stats dependency: the handler computes totalUsers := len(users) from the fully-fetched slice. A fix that limits the main query must compute totalUsers via a separate CountDocuments so the total count isn't broken by the limit. (The other stats like debatesToday already use their own CountDocuments queries, so they're unaffected.)
Steps to Reproduce
- Open
backend/controllers/leaderboard.goand viewGetLeaderboard. - Note
collection.Find(c, bson.M{}, findOptions)has no.SetLimit()— it returns all users. - With many users in the DB, hit the leaderboard endpoint; the full user set is loaded and returned every time (no pagination, no cap).
Logs and Screenshots
backend/controllers/leaderboard.go (GetLeaderboard):
findOptions := options.Find().SetSort(bson.D{{"rating", -1}})
cursor, err := collection.Find(c, bson.M{}, findOptions) // unbounded
...
totalUsers := len(users) // depends on full fetch
Environment Details
- File: backend/controllers/leaderboard.go (GetLeaderboard; unbounded Find ~line 52, totalUsers ~line 95)
- Backend: Go / MongoDB
- Branch: main
- Fix direction: add
.SetLimit(N)(optionally?page/?limit), and replacetotalUsers := len(users)withcollection.CountDocuments(ctx, bson.M{})so the total stays accurate.
Impact
Medium - Feature works but has issues
Code of Conduct
- I have joined the Discord server and will post updates there
- I have searched existing issues to avoid duplicates
- Dominant language
- TypeScript
- Stars
- 104
- Forks
- 244
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 42
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AOSSIE-Org/DebateAI
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
AOSSIE-Org/DebateAI#773 · 2 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
AOSSIE-Org/DebateAI#772 · 1 comment ·
Maintainers usually reply within 1 day
-
[BUG]: Header avatar and display name don't update after editing the profilePossibly taken @mithunkc017-ship-it claimed this 2 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
AOSSIE-Org/DebateAI#770 · 2 comments ·
Maintainers usually reply within 1 day
-
[BUG]: Signed-out visitors see a fake account menu ("User", "No email", "Sign out") on public pagesPossibly taken @dhruvbit claimed this 2 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AOSSIE-Org/DebateAI#769 · 4 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
AOSSIE-Org/DebateAI#768 · 1 comment ·
Maintainers usually reply within 1 day
All issues in AOSSIE-Org/DebateAI
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Merit-Systems/x402scan#1312 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Native Web
Difficulty 1/5 Under an hour Newbie friendliness 80/100
digitalfabrik/integreat-app#4517 ·
Maintainers usually reply within 2 days
-
TLS guide repeats certs/ in the certificate directoryPossibly taken @maheshrijal claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
prometheus/docs#3156 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
medusajs/dtc-starter#90 ·
Maintainers usually reply within 1 day