Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG]: Leaderboard loads all users with no limit or pagination — scalability concern

Closed Beginner friendly
#611 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

A pull request for this has already been merged.

  • #618 by @SamikSwarupBiswal — closed without merging
  • #621 by @RounakKumarAgarwal — merged

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, mongodb
Domain
backend, databases

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
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
  1. Open backend/controllers/leaderboard.go and view GetLeaderboard.
  2. Note collection.Find(c, bson.M{}, findOptions) has no .SetLimit() — it returns all users.
  3. 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 replace totalUsers := len(users) with collection.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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AOSSIE-Org/DebateAI

All issues in AOSSIE-Org/DebateAI

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.