Skip to content

enhancement(scope:backend): Refactor old routes to use unified cache service (retain Redis, remove manual caching) #120

@jonasyr

Description

@jonasyr

🎯 Issue Type

  • Enhancement

📋 Description

Problem/Need

Older endpoints in apps/backend/src/routes/repositoryRoutes.ts still implement their own caching logic: they manually set and get Redis keys and clone a repository via withTempRepository() on each call. This bypasses the Cache Service and HybridLRUCache described in the Caching System documentation. As a result, commit data is cloned multiple times, aggregated data is recomputed unnecessarily, and manual Redis operations ignore tier promotion and cache invalidation semantics.

Expected Behavior

  • All routes should delegate caching to getCachedCommits(), getCachedAggregatedData() and getCachedContributors() from repositoryCache.ts.
  • The unified cache should handle lookups across memory, disk, and Redis tiers, including automatic promotion, fallback, and invalidation.
  • Redis remains part of the storage tier; the change removes only the manual cache handling from route handlers.

Current Behavior

  • Endpoints like POST /api/repositories, /heatmap, /contributors, and /full-data check Redis directly, clone the repository, and recompute commits or aggregations.
  • They do not leverage multi‑tier caching, resulting in duplicated Git operations and inconsistent cache invalidation.

🔄 Steps to Reproduce

  1. Spin up the backend and send a POST to /api/repositories with a repo URL.
  2. Immediately call POST /api/repositories/heatmap with the same URL.
  3. Observe that the second call clones the repo again instead of using cached commit data (logs show duplicate gitService.getCommits() calls).
  4. Compare to the new GET /api/commits and GET /api/commits/heatmap endpoints, which reuse cached data via the cache service.

🎨 Mockups/Screenshots

// Current manual caching (simplified)
const commitsKey = `commits:${repoUrl}`;
const cached = await redis.get(commitsKey);
if (!cached) {
  const commits = await withTempRepository(repoUrl, (dir) => gitService.getCommits(dir));
  await redis.set(commitsKey, JSON.stringify(commits));
}
// Proposed unified caching usage
const cacheOptions: CommitCacheOptions = { skip: 0, limit: 1000 };
const commits = await getCachedCommits(repoUrl, cacheOptions);

See Hybrid LRU Cache – Three‑Tier Storage Architecture for details on memory, disk, and Redis tiers and Cache Service for the unified API.

🧪 Acceptance Criteria

  • Remove manual redis.get/set logic from older routes.
  • Replace direct gitService calls with getCachedCommits, getCachedAggregatedData, and getCachedContributors.
  • Ensure that Redis remains configured as the third tier in cache configuration; only manual calls are removed.
  • Add or update unit/integration tests to confirm that subsequent calls reuse cached data.
  • Document the change in route comments and/or docs, referencing the caching system design.

🛠 Technical Details

Affected Files/Components

  • apps/backend/src/routes/repositoryRoutes.ts
  • apps/backend/src/services/repositoryCache.ts (import/export usage)
  • Test suites for repository routes.

Dependencies

  • None, though ensure configuration (config.ts) still enables Redis if desired.

Breaking Changes

  • Yes
  • No

🏷 Categorization

Scope

  • scope:backend

Priority

  • prio:high

Effort

  • effort:small
  • effort:medium

📝 Additional Notes

  • This refactor does not remove Redis from the caching infrastructure. It aligns the older routes with the multi‑tier cache design, as described in the Cache Invalidation and Hybrid LRU Cache pages.
  • The repository’s cache configuration can still disable Redis if desired via enableRedis, but that change would be separate.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions