feat(core): implement SqliteStatsRepository (closes #36)
Merged
MP
7mo ago+375+375+012345678901234567890123456789-12-12-01234567890123456789
Summary
- Replace
InMemoryStatsRepositorystub withSqliteStatsRepobacked by the existingstatisticstable - Persistent download statistics survive app restarts
- Real
success_rate,daily_volumes, andtop_hostscomputed via SQL aggregation
Changes
- New:
src-tauri/src/adapters/driven/sqlite/stats_repo.rs—SqliteStatsRepoimplementingStatsRepositorytraitrecord_completed: UPSERT daily stats row with running average speed and peak speed trackingget_stats: 4 raw SQL queries aggregating totals, daily volumes, success rate (terminal states only), and top hosts by download volume
- Modified:
src-tauri/src/lib.rs— wireSqliteStatsReporeplacingInMemoryStatsRepository - Modified:
src-tauri/src/adapters/driven/mod.rs— gatestatsmodule behind#[cfg(test)] - Modified:
src-tauri/tests/app_state_wiring.rs— useSqliteStatsRepoin integration test
Test plan
- 6 integration tests with in-memory SQLite (
setup_test_db()) - Empty DB returns zero-state
- Single record inserts correctly
- Multiple records accumulate (bytes, files, avg_speed, peak_speed)
- Daily volumes returned in DESC order
- Success rate computed from terminal states (Completed/Failed/Cancelled)
- Top hosts ordered by total bytes DESC
-
cargo clippy --workspace -- -D warningsclean - 443 tests pass, 0 failures
Summary by cubic
Replaced the in-memory stats stub with SQLite-backed SqliteStatsRepo to persist stats and compute aggregates (totals, daily volumes, success rate, top hosts). Wired into the app and tests; the in-memory repo is now test-only; closes #36.
-
New Features
- Upserts daily stats with a running average speed and peak speed.
-
Bug Fixes
- Use localtime for daily bucketing.
- Compute success rate from terminal states only (
Completed,Error). - Limit top hosts to completed downloads.
- Fix CHANGELOG to reference
SqliteStatsRepo.
Summary by CodeRabbit
-
New Features
- Statistics are now persisted in SQLite by default, with daily aggregates, rolling averages, peak speeds, and per-host summaries retained across sessions.
-
Bug Fixes
- In-memory stats implementation is now only used for unit tests; persistent storage is the default.
-
Tests
- Updated tests to validate persistent statistics, daily aggregation ordering, success-rate computation, and top-host ranking.