feat(activity): implement CRUD operations for daily activity cache #293

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

What

Three new methods on *Cache in cache.go, completing Phase 1 of the activity view feature.

API

  • UpsertDailyActivity(act)INSERT ... ON CONFLICT DO UPDATE SET for idempotent upserts
  • GetActivityWindow(ctxType, ctxID) — queries the 7-day rolling window, returns ActivityWindow with days sorted ASC
  • GetLastFetchTimestamp(ctxType, ctxID) — returns the latest fetched_at for the context, or zero time if no data

Completed

  • ROADMAP2.md — all Phase 1 tasks now marked complete (types, schema, staleness, CRUD)
  • Phase 1 is now fully finished

References: #175, #172, #173, #174

Testing

  • 11 new CRUD tests + 22 existing = 33 total
  • Covers upsert round-trip, upsert update, context isolation, empty window, last fetch with/without data, multi-day ordering
  • golangci-lint run ./internal/activity/ — 0 issues
  • go vet ./internal/activity/ — 0 issues
  • go build ./... && go test ./... — all pass
## What Three new methods on `*Cache` in `cache.go`, completing Phase 1 of the activity view feature. ### API - **UpsertDailyActivity(act)** — `INSERT ... ON CONFLICT DO UPDATE SET` for idempotent upserts - **GetActivityWindow(ctxType, ctxID)** — queries the 7-day rolling window, returns `ActivityWindow` with days sorted ASC - **GetLastFetchTimestamp(ctxType, ctxID)** — returns the latest `fetched_at` for the context, or zero time if no data ### Completed - **ROADMAP2.md** — all Phase 1 tasks now marked complete (types, schema, staleness, CRUD) - **Phase 1 is now fully finished** References: #175, #172, #173, #174 ## Testing - [x] 11 new CRUD tests + 22 existing = 33 total - [x] Covers upsert round-trip, upsert update, context isolation, empty window, last fetch with/without data, multi-day ordering - [x] `golangci-lint run ./internal/activity/` — 0 issues - [x] `go vet ./internal/activity/` — 0 issues - [x] `go build ./... && go test ./...` — all pass
feat(activity): implement CRUD operations for daily activity cache
All checks were successful
Test and Release / lint (pull_request) Successful in 3m46s
Test and Release / test (pull_request) Successful in 9m47s
70aa91a401
- UpsertDailyActivity(): INSERT OR UPDATE using SQLite ON CONFLICT
- GetActivityWindow(): query 7-day window ordered ASC, returns
  ActivityWindow with all metrics
- GetLastFetchTimestamp(): MAX(fetched_at) via SQL COALESCE
- All operations use UTC timestamps serialized as RFC3339
- Tests: upsert round-trip, upsert update, context isolation,
  empty window, last fetch with/without data, multi-day query

This completes all Phase 1 tasks.

Closes #175, #172, #173, #174
the.auditor left a comment

Review

Result: Approved — no blocking issues.

Summary: Completes Phase 1 data layer. Adds three CRUD methods to *Cache: UpsertDailyActivity (INSERT ON CONFLICT DO UPDATE SET), GetActivityWindow (7-day window, ASC order, RFC3339 parsing), GetLastFetchTimestamp (MAX fetched_at, zero when empty). 11 new subtests (33 total) — upsert round-trip, update, context isolation, empty window, last fetch with/without data, multi-day ordering. ROADMAP2.md updated — Phase 1 fully complete.

Non-blocking:

  • #294 — Add godoc for three exported CRUD methods

Checklist:

  • Correctness: Upsert with ON CONFLICT, window query with date range, MAX fetched_at
  • Completeness: All three required CRUD operations implemented (#172, #173, #174)
  • Test coverage: 11 subtests covering round-trip, update, isolation, empty, multi-day
  • Error handling: Errors wrapped, rows closed via defer, rows.Err() checked, parse errors handled
  • Performance: Single queries, parameterized, index on context columns
  • Maintainability: Clean SQL builder pattern, consistent RFC3339 format
## Review **Result: Approved** — no blocking issues. **Summary:** Completes Phase 1 data layer. Adds three CRUD methods to `*Cache`: `UpsertDailyActivity` (INSERT ON CONFLICT DO UPDATE SET), `GetActivityWindow` (7-day window, ASC order, RFC3339 parsing), `GetLastFetchTimestamp` (MAX fetched_at, zero when empty). 11 new subtests (33 total) — upsert round-trip, update, context isolation, empty window, last fetch with/without data, multi-day ordering. ROADMAP2.md updated — Phase 1 fully complete. **Non-blocking:** - #294 — Add godoc for three exported CRUD methods **Checklist:** - Correctness: ✅ Upsert with ON CONFLICT, window query with date range, MAX fetched_at - Completeness: ✅ All three required CRUD operations implemented (#172, #173, #174) - Test coverage: ✅ 11 subtests covering round-trip, update, isolation, empty, multi-day - Error handling: ✅ Errors wrapped, rows closed via defer, rows.Err() checked, parse errors handled - Performance: ✅ Single queries, parameterized, index on context columns - Maintainability: ✅ Clean SQL builder pattern, consistent RFC3339 format
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-07-07 08:21:01 +00:00
fuzzy merged commit 70aa91a401 into main 2026-07-07 08:29:15 +00:00
fuzzy deleted branch phase01-crud 2026-07-07 08:29: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!293
No description provided.