Skip to content

feat: persist PR cache to UserDefaults for instant startup display#15

Merged
SeanMcTex merged 2 commits into
mainfrom
feature/cache-persistence
May 11, 2026
Merged

feat: persist PR cache to UserDefaults for instant startup display#15
SeanMcTex merged 2 commits into
mainfrom
feature/cache-persistence

Conversation

@SeanMcTex
Copy link
Copy Markdown
Owner

@SeanMcTex SeanMcTex commented May 11, 2026

Summary

  • PullRequest (and its nested RepositoryInfo, Author, Label types) gains Codable conformance
  • New PRCacheService saves/restores main and Other PR lists as JSON in UserDefaults; uses an in-session Data.hashValue guard to skip redundant writes
  • PRMonitorViewModel restores from cache before the first poll so the menu bar shows real data immediately on launch, then saves after each successful refresh

Review fixes (follow-up commit)

  • restoreFromCache() now re-applies WatchlistService truth over cached isWatched values, eliminating a stale-state window on startup
  • Extracted private load<T>(forKey:) helper in PRCacheService to remove loadMainPRs/loadOtherPRs duplication
  • Added PRCacheServiceTests (7 tests) covering round-trip, field fidelity, overwrite, empty-list clearing, and hash-guard correctness

User-facing impact

Eliminates the blank PR list on startup. The previous session's data appears instantly; the list refreshes in place once the first GitHub fetch completes.

Credit

Feature originally implemented by @zhengbuqian in #8. Cherry-picked and adapted for the main branch.

Test plan

  • Unit tests: PRCacheServiceTests (7 tests, all passing)
  • Launch app cold — PR list should populate immediately from cache before first refresh completes
  • Verify first refresh updates the list correctly (no stale data stuck)
  • Quit and relaunch — cached data should survive the process boundary
  • On first-ever launch (no cache), verify no crash and normal empty→populated flow

🤖 Generated with Claude Code

SeanMcTex and others added 2 commits May 11, 2026 13:53
On launch, restores the previous session's PR list immediately so the
menu bar shows real data while the first GitHub fetch is in flight,
eliminating the blank-list flash on startup.

- PullRequest (and nested types) gains Codable conformance
- New PRCacheService saves/restores main and Other PR lists as JSON;
  uses an in-session Data.hashValue guard to skip redundant writes
- PRMonitorViewModel restores from cache before first poll, then saves
  after each successful refresh

Co-authored-by: Buqian Zheng <zhengbuqian@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add PRCacheServiceTests (7 tests) covering round-trip, field fidelity,
  overwrite, empty-list clearing, and hash-guard correctness
- Fix restoreFromCache() to re-apply WatchlistService truth over cached
  isWatched values, eliminating the stale-state window on startup
- Extract private load<T>(forKey:) helper in PRCacheService to remove
  the loadMainPRs/loadOtherPRs duplication

Co-Authored-By: zhengbuqian <zhengbuqian@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SeanMcTex SeanMcTex merged commit a8dddf1 into main May 11, 2026
@SeanMcTex SeanMcTex deleted the feature/cache-persistence branch May 11, 2026 21:27
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.

1 participant