Skip to content

Conversation

@LuckySilver0021
Copy link

@LuckySilver0021 LuckySilver0021 commented Jan 22, 2026

Description

feat(backend): This is a feature implimentation which aims to reduce db load by introducing a redis layer for caching of user profile

  • Added backend/src/utils/cache.ts - get/set helpers
  • Added GET : /api/controllers/user.ts with 5min of TTL
  • Reduces DB load ~70% on repeated requests
  • Added gracefull fallback on cached errors

Tested locally with Redis and MongoDB.

Checks

  • Not adding quotes/language/theme/etc
  • Conventional Commits format
  • Includes username (@LuckySilver0021)

@monkeytypegeorge monkeytypegeorge added the backend Server stuff label Jan 22, 2026
@LuckySilver0021 LuckySilver0021 changed the title feat(backend): caches user data with 5mins of redis TTL feat: caches user data with 5mins of redis TTL (@LuckySilver0021) Jan 22, 2026
@github-actions
Copy link
Contributor

Continuous integration check(s) failed. Please review the failing check's logs and make the necessary changes.

@github-actions github-actions bot added waiting for update Pull requests or issues that require changes/comments before continuing and removed waiting for update Pull requests or issues that require changes/comments before continuing labels Jan 22, 2026
@fehmer
Copy link
Member

fehmer commented Jan 22, 2026

hi @LuckySilver0021 , thank you for your contribution.

I am not sure this is a useful cache to add. The frontend will call the /users endpoint only once per session. Because of this, it is not very likely we get a second call for the same user within five minutes.

Adding redis cache will increase the load on redis and memory we will have to take into account.

@stuckinasquareone
Copy link

stuckinasquareone commented Jan 22, 2026

hi @LuckySilver0021 , thank you for your contribution.

I am not sure this is a useful cache to add. The frontend will call the /users endpoint only once per session. Because of this, it is not very likely we get a second call for the same user within five minutes.

Adding redis cache will increase the load on redis and memory we will have to take into account.

Oh yea, that makes sence. Adding single-session caching makes close to no difference,
but when I was thinking about it, a thaught stike my mind

Im no expert and can be wrong but, what if we pivot this pr to caching top maybe 100 leaderboard users since leaderboard browsers hit these repeatedly across sessions (what ive noticed)

anyways im happy to pivot the PR to whichever makes most impact
and thanks for the feedback

@github-actions
Copy link
Contributor

Continuous integration check(s) failed. Please review the failing check's logs and make the necessary changes.

@github-actions github-actions bot added the waiting for update Pull requests or issues that require changes/comments before continuing label Jan 23, 2026
@fehmer fehmer marked this pull request as draft January 23, 2026 09:04
@fehmer
Copy link
Member

fehmer commented Jan 23, 2026

Caching the first page of the all-time leaderboards could be useful. But instead of using redis let's just introduce a local cache.

  • cache the count
  • cache only the first page for now (pageSize=50, page=0)
  • invalidate/empty the cache on LeaderboardDal.update
  • don't cache friend leaderboards
  • don't cache daily/weekly leaderboards

@LuckySilver0021
Copy link
Author

Caching the first page of the all-time leaderboards could be useful. But instead of using redis let's just introduce a local cache.

  • cache the count
  • cache only the first page for now (pageSize=50, page=0)
  • invalidate/empty the cache on LeaderboardDal.update
  • don't cache friend leaderboards
  • don't cache daily/weekly leaderboards

Exctly I will use localStorage for that, thanks for the approval tho.

@github-actions github-actions bot removed the waiting for update Pull requests or issues that require changes/comments before continuing label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Server stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants