Add dashboard ClickHouse read models
Merged
AS
6mo ago+1432+1432+0123456789012345678901234567890123456789-789-789-012345678901234567890123456789
Summary
- Add dbt-owned ClickHouse read models for healthspan, recovery, and strain so dashboard APIs read compact serving tables instead of recomputing dashboard metrics per request.
- Switch recovery, stress, sleep need, mobile dashboard, and healthspan query paths to the new read models, using
FINALwhere freshness depends onReplacingMergeTree. - Add ClickHouse table creation, dbt safe-model ordering, test helper coverage, and docs for the dashboard serving layer.
Verification
set -a; . ./.env.local; set +a; pnpm lintpnpm tsc --noEmitcd packages/server && pnpm tsc --noEmitcd packages/web && pnpm tsc --noEmitset -a; . ./.env.local; set +a; pnpm test --run
Summary by cubic
Adds ClickHouse dashboard read models for recovery, strain, and healthspan, and switches related routes to read compact tables to cut latency and database load. Incremental builds are now micro-batched and bounded per user/day/week to avoid backfills; healthspan uses VO2 started date and strain date filters are timezone-safe.
-
New Features
- Added read models:
analytics.recovery_read_model,analytics.strain_read_model,analytics.healthspan_read_modelusingReplacingMergeTree(refresh_version)with bounded incremental materialization; routes useFINALwhere needed. - Switched recovery, stress (incl. strength-stress), sleep-need, mobile dashboard, and healthspan APIs to these models; strain queries pass the user timezone; simplified the healthspan query path.
- Added read models:
-
Migration
- Run ClickHouse migrations, including
0026_create_named_dashboard_read_model_tables.ts, then rebuild dbt models with the updated safe model list. - No API surface changes or client updates required.
- Run ClickHouse migrations, including
Summary by CodeRabbit
- New Features
- Added dedicated precomputed dashboard models serving Recovery, Strain, and Healthspan metrics for route-facing queries.
- Performance Improvements
- Dashboard metrics for recovery, strain, and healthspan now load from compact read models, reducing request-time aggregation and latency.
- Documentation
- Updated analytics and deploy docs and added a production incident entry describing the change and mitigation.
- Tests & Maintenance
- Added migration and test coverage for the new read models and updated integration/unit tests.