perf(statistics): reduce query load on large installs - #865
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. WalkthroughThe Statistics page now reduces database joins and chart queries, adds an index for subscription history, limits the initial history range, slows polling, and adds SQLite coverage and performance documentation. ChangesStatistics performance changes
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This reduces Statistics-page query volume and polling frequency while retaining scoped query behavior and explicit all-time history selection. Current evidence indicates the change is ready to merge. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 7 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
/api/users/sub_update/chartfrom two history aggregations to one by deriving pie totals from the period rowsusersjoins from owner-wide subscription history and unscoped online-count queriescreated_atindex for owner-wideuser_subscription_updatestime rangesCloses #858
Type of change
Checklist
Testing
.venv/Scripts/python.exe -m pytest -q tests/test_statistics_query_load.py tests/test_system_user_metrics.py tests/api/test_usage_functions_timezone.py— 32 passednpm run buildindashboard— passedalembic upgrade head, downgrade to7c4bd5128e62, and upgrade again — passed; the new index appeared, disappeared, and reappeared as expectedCREATE INDEX idx_user_subscription_updates_created_at ON user_subscription_updates (created_at)Directional in-memory SQLite benchmark, 400,000 rows per history table, median of seven warmed runs:
These numbers validate direction and query shape; they are not a production MySQL latency guarantee. The reporter's offered
EXPLAIN ANALYZEoutput remains the best follow-up validation on the affected installation.The three standalone
tests/api/test_user.pypermission cases were also attempted, but the current API harness did not seed thetestadminlogin and failed in the existingaccess_tokenfixture before reaching the endpoint. The operation path and response equivalence are covered by the new database-backed test.Screenshots
Not applicable. The UI changes only adjust polling and the initial time range; layout is unchanged.
Notes for reviewers
I checked related prior and in-flight work before implementing this:
/api/system/usersto one SQL statement; this PR keeps it and reduces how often the full aggregate runs on the Statistics page.The new index must scan the existing subscription-update table. Large MySQL/MariaDB installations should apply this migration during a maintenance window because DDL locking depends on server version and table configuration. All-time history remains available as an explicit chart selection.
Summary by CodeRabbit
Performance
Usability
Documentation
Tests