perf(server): use monthly serving models - #2029
Conversation
Reuse activity summary freshness and cap dirty-key batches so analytics cycles do not expand the entire power backlog. Consume precomputed normalized power during refits.
# Conflicts: # docs/production-incident-baseline.md
Treat partial and runtime failures as failed while allowing intentional no-op results. Fixes DOFEK-SERVER-5D.
Avoid recursive ClickHouse views on the request path and verify the compact-model query against a real database. Fixes DOFEK-SERVER-5C.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
PR Summary by QodoUse ClickHouse serving models for monthly report queries
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
📝 WalkthroughWalkthroughMonthly report aggregation now uses timezone-aware bucketing and compact finalized sleep/recovery serving tables instead of recursive analytics views. A ClickHouse integration test validates the report without those views, and production incident documentation records the mitigation and follow-up. ChangesMonthly report read-model update
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
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 |
|
Storybook previews for This comment updates automatically on each PR push. |
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/production-incident-baseline.md`:
- Line 17965: Rename the incident heading “2026-07-26 — Monthly Report
Recomputed Recursive Analytics Views” to state that the monthly report query
replaced recursive analytics views, reflecting the actual mitigation.
In `@packages/server/src/repositories/monthly-report-repository.ts`:
- Around line 128-130: Make report boundaries timezone-aware in the monthly
report query anchored by the per_activity CTE: derive local report-date/month
start and end values from {timezone:String} and reuse them consistently for
activity, sleep, recovery, and date_series ranges. In
packages/server/src/repositories/monthly-report-repository.integration.test.ts
lines 93-108, add a non-UTC month-boundary fixture including deleted and
superseded serving rows, and assert the resulting aggregates to cover the
corrected behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c732e4ae-86aa-450a-a71b-eab3606b6b0e
📒 Files selected for processing (3)
docs/production-incident-baseline.mdpackages/server/src/repositories/monthly-report-repository.integration.test.tspackages/server/src/repositories/monthly-report-repository.ts
Code Review by Qodo
Context used✅ Compliance rules (platform):
164 rules✅ Skills:
fix-provider, write-tests, cloudflare 1.
|
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
Summary
Production evidence
Validation
pnpm test:integration -- packages/server/src/repositories/monthly-report-repository.integration.test.tspnpm exec vitest run packages/server/src/repositories/monthly-report-repository.test.tspnpm typecheckpnpm --dir packages/server typecheckFixes DOFEK-SERVER-5C.
Summary by cubic
Switch the monthly report to ClickHouse serving models to eliminate timeouts and cut query time from ~120s to ~0.101s. Fixes DOFEK-SERVER-5C with no changes to the response shape.
Bug Fixes
analytics.activity_summary, sleep fromanalytics.daily_sleep FINAL, and recovery fromanalytics.daily_recovery FINAL; removed recursive views and the resting‑HR CTE.Refactors
Written for commit fbdb8db. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests
Documentation