Skip to content

Bound the cache warming repository reads in CacheWarmingService #1053

Description

@RUKAYAT-CODER

Overview

src/caching/cache-warming.service.ts issues five repository reads (lines 55, 85, 92, 132, 139) against the courses and users tables with no take. Cache warming runs on a schedule and on startup, so at each invocation the service loads a full table into memory in order to populate the cache with entries that, by definition, have a bounded useful size. On a large dataset a warming pass can consume more memory than the cache it is filling, and because it runs at startup it competes with the application's own initialisation for both memory and database connections.

Specifications

Features:

  • Warming reads a bounded, prioritised working set.
  • Warming is throttled so it does not compete with live traffic.

Tasks:

  • Add an explicit take to each read, sized from a configurable CACHE_WARM_MAX_ENTRIES.
  • Prioritise the warmed set by a real signal — enrollment count for courses, recent activity for users — rather than reading everything.
  • Process the working set in batches with a small delay between them to bound database and memory pressure.
  • Emit metrics for entries warmed and warming duration.
  • Defer startup warming until after the server is accepting traffic.

Impacted Files:

  • src/caching/cache-warming.service.ts
  • src/caching/cache-warming.scheduler.ts

Acceptance Criteria

  • No warming query reads an unbounded result set.
  • The warmed set is selected by a documented priority signal.
  • Warming duration and entry count are exported as metrics.
  • Startup warming does not delay readiness.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions