Skip to content

fix: read user settings fresh instead of from a per-process cache - #334

Merged
HardMax71 merged 1 commit into
mainfrom
fix/user-settings-cache
Oct 11, 2026
Merged

HardMax71 merged 1 commit into
mainfrom
fix/user-settings-cache

Conversation

@HardMax71

@HardMax71 HardMax71 commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

The user settings service kept a 5-minute cache in each API process, and the API container runs two gunicorn workers (WEB_CONCURRENCY defaults to 2 in the Dockerfile). A read that landed on the other worker after an update returned the old settings for up to 5 minutes. An update handled there merged onto that stale copy too, so its response could carry an old theme. I hit it while checking #333 in a browser: right after toggling the theme, the GET sometimes answered with the previous one. Once #333 merges, the frontend applies the theme from the settings query on every refetch, so this would show as a theme flipping back.

Every read now rebuilds from the latest snapshot and the events after it. That's two MongoDB queries and at most ten events, since a snapshot is written every ten. cachetools had no other user, so it's dropped from the dependencies.

The new unit test runs two services over one store, standing in for two workers, and fails on main (auto == dark). The e2e test that only checked the cache hit is replaced by one that reads right after an update. Unit tests, ruff, mypy and the orphan check pass. The non-k8s e2e suite passes apart from the usual k3s-only saga, notification and SSE tests.


Summary by cubic

Fixes stale user settings when an update goes through one API worker and a read hits another, since each worker kept its own 5-minute cache. Reads now rebuild from the latest snapshot and the events after it, so updates are visible immediately; updates no longer merge onto a stale cached copy.

  • Removed the per-process TTLCache and the now-unused cachetools and types-cachetools dependencies.
  • Each read costs two MongoDB queries and at most ten events, since a snapshot follows every ten.
  • Replaced the e2e cache-hit test with one that reads right after an update, and added a unit test where a second service stands in for another worker.
  • Updated architecture docs to match.

Written for commit 5b08771. Summary will update on new commits.

View guided diff Turn on auto-fix

The settings service kept a 5-minute cache in each API process, and the API runs two gunicorn workers. A read that landed on the other worker after an update returned the old settings, and so did an update's response, since it merged onto the cached copy. Every read now rebuilds from the snapshot and the events after it, which is two MongoDB queries and at most ten events. cachetools had no other user, so it's gone too.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 93a3d3f6-20ed-4a96-b5c4-e8a5c653b308

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added documentation Improvements or additions to documentation area: api FastAPI routes, auth, rate limiting, settings labels Oct 11, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codecov-commenter

codecov-commenter commented Oct 11, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Flag Coverage Δ
backend-e2e 82.87% <100.00%> (-0.08%) ⬇️
backend-unit 72.33% <100.00%> (-0.02%) ⬇️
frontend-unit 87.85% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/app/services/user_settings_service.py 98.73% <100.00%> (-0.23%) ⬇️

... and 1 file with indirect coverage changes

Components Coverage Δ
Backend 91.35% <100.00%> (-0.03%) ⬇️
Frontend 87.85% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@HardMax71
HardMax71 merged commit 1acecfc into main Oct 11, 2026
21 checks passed
@HardMax71
HardMax71 deleted the fix/user-settings-cache branch October 11, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: api FastAPI routes, auth, rate limiting, settings documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants