feat(activity): add cache TTL and staleness logic #291

Merged
fuzzy merged 1 commit from phase01-staleness into main 2026-07-07 08:14:15 +00:00
Owner

What

Add internal/activity/staleness.go with cache TTL and staleness logic for the daily activity cache.

Functions

  • isDateImmutable(date) — returns true if date is before today UTC. Past dates are treated as immutable sources of truth.
  • isCacheStale(fetchedAt, date) — returns true if the cache entry needs refreshing. Past dates are never stale; today is stale if time.Since(fetchedAt) > CurrentDateTTL (5 minutes).
  • GetRefreshWindow(days) — walks the 7-day window backwards, returns the earliest stale/missing date as the API since timestamp. Returns (zero, false) if all dates are fresh.

Updated

  • ROADMAP2.md — marked #181, #176, and #185 (with sub-tasks) as complete

References: #185, #182, #183, #184

Testing

  • 15 new subtests + 7 existing = 22 total pass
  • golangci-lint run ./internal/activity/ — 0 issues
  • go vet ./internal/activity/ — 0 issues
  • go build ./... passes
## What Add `internal/activity/staleness.go` with cache TTL and staleness logic for the daily activity cache. ### Functions - **isDateImmutable(date)** — returns true if date is before today UTC. Past dates are treated as immutable sources of truth. - **isCacheStale(fetchedAt, date)** — returns true if the cache entry needs refreshing. Past dates are never stale; today is stale if `time.Since(fetchedAt) > CurrentDateTTL` (5 minutes). - **GetRefreshWindow(days)** — walks the 7-day window backwards, returns the earliest stale/missing date as the API `since` timestamp. Returns `(zero, false)` if all dates are fresh. ### Updated - **ROADMAP2.md** — marked #181, #176, and #185 (with sub-tasks) as complete References: #185, #182, #183, #184 ## Testing - [x] 15 new subtests + 7 existing = 22 total pass - [x] `golangci-lint run ./internal/activity/` — 0 issues - [x] `go vet ./internal/activity/` — 0 issues - [x] `go build ./...` passes
feat(activity): add cache TTL and staleness logic
All checks were successful
Test and Release / test (pull_request) Successful in 3m43s
Test and Release / lint (pull_request) Successful in 4m19s
42388db219
- isDateImmutable(): dates before today UTC are immutable (never stale)
- isCacheStale(): checks CurrentDateTTL for today, returns false for
  immutable dates
- GetRefreshWindow(): walks 7-day window backwards, returns earliest
  stale/missing date as the API since parameter
- All three functions are unexported (internal to activity package)
- 15 new subtests covering immutability, staleness, empty/missing data

Ref: #185, #182, #183, #184
the.auditor left a comment

Review

Result: Approved — no blocking issues.

Summary: Adds internal/activity/staleness.go with cache TTL logic: isDateImmutable (past dates never stale), isCacheStale (today's TTL vs CurrentDateTTL), and GetRefreshWindow (walks 7-day window returning earliest stale/missing date as API since parameter). 15 subtests covering all paths including empty cache, missing dates, stale today, and fresh cache.

Non-blocking:

  • #292 — Add godoc for exported GetRefreshWindow

Checklist:

  • Correctness: UTC-based date comparisons, safe defaults on parse errors
  • Completeness: All three functions from #185 implemented and tested
  • Test coverage: 15 subtests — immutability, staleness, refresh-window edge cases (all fresh, missing, stale today, empty)
  • Error handling: Parse errors on date string return safe defaults (mutable, refreshable)
  • Maintainability: Clean, simple pure functions, easy to reason about
## Review **Result: Approved** — no blocking issues. **Summary:** Adds `internal/activity/staleness.go` with cache TTL logic: `isDateImmutable` (past dates never stale), `isCacheStale` (today's TTL vs CurrentDateTTL), and `GetRefreshWindow` (walks 7-day window returning earliest stale/missing date as API since parameter). 15 subtests covering all paths including empty cache, missing dates, stale today, and fresh cache. **Non-blocking:** - #292 — Add godoc for exported `GetRefreshWindow` **Checklist:** - Correctness: ✅ UTC-based date comparisons, safe defaults on parse errors - Completeness: ✅ All three functions from #185 implemented and tested - Test coverage: ✅ 15 subtests — immutability, staleness, refresh-window edge cases (all fresh, missing, stale today, empty) - Error handling: ✅ Parse errors on date string return safe defaults (mutable, refreshable) - Maintainability: ✅ Clean, simple pure functions, easy to reason about
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-07-07 08:11:46 +00:00
fuzzy merged commit 42388db219 into main 2026-07-07 08:14:15 +00:00
fuzzy deleted branch phase01-staleness 2026-07-07 08:14:15 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/steeper!291
No description provided.