Repository navigation
feat(fetcher): introduce RealtimeFetcher trait for clock-like widgets - #37
Conversation
Fetchers whose value is intrinsically "right now" (wall clock, instantaneous counters, countdowns) shouldn't go through the TTL-based disk cache — caching a timestamp for 60s meant a cache-warm splash showed a minute-old clock. Adds a sync `RealtimeFetcher` trait (contract: <1ms, infallible, no I/O) and teaches the Registry to hold both kinds under one name-keyed lookup. Runtime splits trust-passed widgets by kind: cached widgets go through the existing daemon + disk cache path unchanged, realtime widgets recompute on every frame and never touch disk. Migrates `ClockFetcher` and `TodayStub` to the new trait. Daemon's `fetch_and_persist` skips realtime widgets (nothing to persist). First-run wait promotion now only triggers when there are cached widgets expecting data, so a clock-only config no longer forces the full wait window. Closes #36 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe PR introduces a Changes
Sequence DiagramsequenceDiagram
actor User
participant Runtime as Runtime
participant Registry
participant CachedFetcher as Cached Fetcher
participant RealtimeFetcher as Realtime Fetcher
participant Cache as Disk Cache
User->>Runtime: Request payload (first frame)
Runtime->>Registry: get_cached(name) / get_realtime(name)
alt Cached Widget
Registry-->>Runtime: Some(Cached fetcher)
Runtime->>Cache: Load cached entry
alt Cache hit & fresh
Cache-->>Runtime: Payload
else Cache miss or stale
Runtime->>CachedFetcher: fetch() async
CachedFetcher-->>Runtime: Result<Payload>
Runtime->>Cache: Persist payload
end
else Realtime Widget
Registry-->>Runtime: Some(Realtime fetcher)
Runtime->>RealtimeFetcher: compute()
RealtimeFetcher-->>Runtime: Payload (no disk I/O)
end
Runtime-->>User: Rendered output
User->>Runtime: Refresh (next frame)
Runtime->>Registry: get_cached(name) / get_realtime(name)
alt Cached Widget
Runtime->>Cache: Check TTL, refresh if expired
else Realtime Widget
Runtime->>RealtimeFetcher: compute() again
RealtimeFetcher-->>Runtime: Fresh payload
end
Runtime-->>User: Updated output
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #36
Summary
Why not `CachePolicy` on the existing trait?
A realtime fetcher that accidentally does `reqwest` inside `async fetch` would silently block the frame loop. Separate sync trait makes the "no I/O, fast" contract type-enforced.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit