Skip to content

chore: add (leaderboard_id, deleted_at, score) index to leaderboard_entries#5043

Merged
wescopeland merged 2 commits into
RetroAchievements:masterfrom
wescopeland:leaderboard-entries-add-index
Jul 10, 2026
Merged

chore: add (leaderboard_id, deleted_at, score) index to leaderboard_entries#5043
wescopeland merged 2 commits into
RetroAchievements:masterfrom
wescopeland:leaderboard-entries-add-index

Conversation

@wescopeland

Copy link
Copy Markdown
Member

Pre-req for V2 API stuff. It's desirable to have a user leaderboard entries relation endpoint that displays ranks, but unless we have this index, the query from a cold cache hit is slow enough to be a potential DoS vector.

The index on my local occupies roughly 540MB of space.

@wescopeland
wescopeland requested a review from a team July 3, 2026 17:59
@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — online DDL with no locking, straightforward index addition.

Simple, additive migration using non-blocking online DDL. No data modification, no schema breaking changes.

No files require special attention.

Reviews (2): Last reviewed commit: "Merge branch 'master' into leaderboard-e..." | Re-trigger Greptile

@wescopeland
wescopeland enabled auto-merge (squash) July 10, 2026 21:38
@wescopeland
wescopeland merged commit fc64632 into RetroAchievements:master Jul 10, 2026
22 checks passed
wescopeland added a commit that referenced this pull request Jul 10, 2026
… entries (#5045)

Accompanies #5043.

This PR adds a user-scoped leaderboard entries relationship endpoint
that supports a `gameId` filter. This is intended to allow clean
migration from API_GetUserGameLeaderboards.

```
GET /api/v2/users/{user}/leaderboard-entries
GET /api/v2/users/{user}/leaderboard-entries?filter[gameId]=1,2,3
GET api/v2/users/{user}/leaderboard-entries?include=leaderboard.games
```

**Things worth noting:**
1. Each entry's `rank` is computed with a correlated subquery mirroring
V1's `calculated_rank`, since a user's entries span many leaderboards.
The subquery leans on the index added in #5043.
2. The subquery excludes untracked users in rank calculations.
3. GETs against untracked users (`{user}`) return an empty list.
4. Hidden leaderboards, hub/event games, and soft-deleted
leaderboards/entries are excluded, consistent with
`/leaderboards/{id}/entries`.
5. `filter[gameId]` is comma-delimited.
6. Default sort is leaderboard ID ascending.
7. `?include=leaderboard.games` is allowed for tying entries back to
games. Include paths are listed explicitly rather than via `maxDepth:
2`. The plural `games` is intentional and matches the existing
`leaderboards` resource - anticipating that leaderboards can potentially
be attached to multiple games/sets per leaderboard ID.
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.

2 participants