Skip to content

feat(perf): add client-side caching for dashboard API responses (#2436)#2470

Open
anuragbraveboy-sudo wants to merge 1 commit into
Umbrella-io:mainfrom
anuragbraveboy-sudo:feat/dashboard-caching
Open

feat(perf): add client-side caching for dashboard API responses (#2436)#2470
anuragbraveboy-sudo wants to merge 1 commit into
Umbrella-io:mainfrom
anuragbraveboy-sudo:feat/dashboard-caching

Conversation

@anuragbraveboy-sudo

Copy link
Copy Markdown

Overview

This PR implements client-side caching for dashboard API responses to eliminate redundant fetches, minimize network overhead, and deliver instant layout navigation.

Closes #2436


Detailed Changes

  • Cache Interception (src/components/DashboardHeader.tsx):
    • Injects a cache layer into the global window.fetch inside DashboardSyncProvider.
    • Implements a memory-based cache lookup that returns cached data instantly while refreshing stale data in the background (Stale-While-Revalidate pattern).
    • Deduplicates concurrent flight requests for identical endpoints using a promise queue.
    • Clears cached metrics automatically on data mutation requests (POST/PUT/DELETE/PATCH) and when manual/realtime sync events (devtrack:sync) are dispatched.
    • Configures stale times per endpoint (5 minutes for metrics, 1 minute for notifications, 2 minutes default).
    • Detects test runs (process.env.NODE_ENV === "test") and returns early to prevent mock pollution in unit tests.
  • Unit Tests Refactoring:
    • test/useUserSettings.test.tsx: Updated mock assertions to properly expect a single mount-level fetch in the testing environment.
    • test/weekly-digest-cron-auth.test.ts: Safely stubbed out the process-level GITHUB_TOKEN to empty during test runs, preventing live metrics fetches from polluting mock assertions.

Verification Results

Verified that all modified tests and checks pass:

  • npm run type-checkPassed
  • npx vitest run test/useUserSettings.test.tsx test/weekly-digest-cron-auth.test.tsPassed (15/15 tests passed)

…ella-io#2436)

- Intercept the global window.fetch in DashboardSyncProvider to implement client-side caching (stale-while-revalidate).

- Configured configurable stale times per endpoint (5m for metrics, 1m for notifications, 2m default).

- Support instant cache loading on navigation, background revalidation, and request deduplication.

- Auto-invalidate cache on mutation requests (POST/PUT/DELETE/PATCH) or devtrack:sync events.

- Safely bypass cache interception during tests (process.env.NODE_ENV === 'test').

- Update test/useUserSettings.test.tsx and test/weekly-digest-cron-auth.test.ts to support caching behavior.
@github-actions github-actions Bot added type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts) type:design GSSoC type bonus: UI/design (+10 pts) type:performance GSSoC type bonus: performance (+15 pts) gssoc26 GSSoC 2026 contribution labels Jun 15, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:design GSSoC type bonus: UI/design (+10 pts) type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PERF] Add Client-Side Caching for Dashboard API Responses to Reduce Redundant Fetches

1 participant