Skip to content

Add reddis cache for leaderboard summaries#210

Open
yangw-dev wants to merge 15 commits intomainfrom
addcache
Open

Add reddis cache for leaderboard summaries#210
yangw-dev wants to merge 15 commits intomainfrom
addcache

Conversation

@yangw-dev
Copy link
Collaborator

@yangw-dev yangw-dev commented Feb 27, 2026

By default, we still use the original logics, and enable cache if v1_query exists.

Cache leaderboard top 3 users only when leaderboard is ended.

Run with cache:
http://localhost:5000/home?use_beta

forch refresh: recalculate everything. this should exist just in case, ended leaderboard need refresh for deleted submission etc

http://localhost:5000/home?use_beta&force_refresh

@yangw-dev yangw-dev requested a review from msaroufim February 27, 2026 00:02
@msaroufim msaroufim temporarily deployed to kernelboard-addcache-lf89dj22k February 27, 2026 00:04 Inactive

try:
key = f"{CACHE_KEY_PREFIX}{leaderboard_id}"
redis_conn.set(key, json.dumps(top_users))
Copy link
Member

@msaroufim msaroufim Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one issue here is we sometimes reopen leaderboards and we frequently extend deadlines

Copy link
Collaborator Author

@yangw-dev yangw-dev Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we extend deadline, it will be recognized as active leaderboard, it will fetch as active leaderboard

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we'd need to call force rest cache IIUC

Copy link
Collaborator Author

@yangw-dev yangw-dev Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see,my bad,
here is updated logics.

  1. make sure to remove active leaderboard from cache if it's active now
  2. cache all ended leaderboard
  3. query all active leaderboard
  4. merge all leaderboard results

when leaderboard ended, it will be cached again.

@msaroufim msaroufim temporarily deployed to kernelboard-addcache-lf89dj22k February 27, 2026 00:16 Inactive
@msaroufim msaroufim temporarily deployed to kernelboard-addcache-lf89dj22k February 27, 2026 00:52 Inactive
@yangw-dev yangw-dev requested a review from msaroufim February 27, 2026 00:53
@msaroufim msaroufim temporarily deployed to kernelboard-addcache-lf89dj22k February 27, 2026 00:54 Inactive
@msaroufim msaroufim temporarily deployed to kernelboard-addcache-lf89dj22k February 27, 2026 00:59 Inactive
@msaroufim msaroufim temporarily deployed to kernelboard-addcache-lf89dj22k February 27, 2026 01:20 Inactive
@yangw-dev
Copy link
Collaborator Author

@msaroufim

  1. add singleton instance for redis connect in general
  2. add force_fresh can only works if and only user is logged in and is admin
  3. update the logics to remove cached leaderboard from redis if it's re-active
  4. fix the ids

@msaroufim msaroufim temporarily deployed to kernelboard-addcache-lf89dj22k February 27, 2026 01:35 Inactive
@msaroufim
Copy link
Member

Alright let's merge this. I am a tiny bit spooked about how this'll work in practice though. But let's monitor and improve for now. Cc @S1ro1

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