Skip to content

fix(caching): bound and prioritise cache warming repository reads - #1409

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
chainsmt:feat/issue-1053
Aug 31, 2026
Merged

fix(caching): bound and prioritise cache warming repository reads#1409
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
chainsmt:feat/issue-1053

Conversation

@chainsmt

Copy link
Copy Markdown
Contributor

Bounds all cache-warming repository reads and prevents startup warming from delaying readiness.

  • Cap every warming query with an explicit take sized from a configurable CACHE_WARM_MAX_ENTRIES (ConfigService/env, default 100); replaces the unbounded published-courses find that loaded the whole table into memory.
  • Select the warmed set by a real priority signal: published courses ranked by enrollment count (createdAt tie-breaker), users by most-recent activity (lastLoginAt DESC).
  • Process the working set in bounded batches (CACHE_WARM_BATCH_SIZE, default 25) with a short delay between batches (CACHE_WARM_BATCH_DELAY_MS, default 50ms) to bound DB/memory pressure.
  • Export warming metrics: cache_warm_entries_total, cache_warm_last_entries, and cache_warm_duration_seconds.
  • Defer startup warming from a blocking OnModuleInit to OnApplicationBootstrap dispatched via setImmediate (not awaited), so warming runs after the server is accepting traffic and never delays readiness.

Testing

  • npx tsc --noEmit — clean
  • npm run lint — clean
  • npx jest src/caching/cache-warming — 2 suites, 10 tests pass (bounding cap, enrollment ordering, batching/delay, metrics, deferred non-blocking bootstrap). Pre-existing unrelated caching spec failures are unchanged.

Closes #1053

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@chainsmt Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 3431de2 into rinafcode:main Aug 31, 2026
3 checks passed
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.

Bound the cache warming repository reads in CacheWarmingService

2 participants