Repository navigation
perf(statistics): reduce query load on large installs - #865
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
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 Suggested reviewers: 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. 🚥 Pre-merge checks | ✅ 4 | ❌ 1
✨ Finishing Touches
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. A rabbit reads each line, Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
remove docs |
|
Done |
|
Note Unit test generation is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
Failed to create Coding Agent finishing-touch task. |
f89d62d to
e16fa51
Compare
…he current head The migration branched off an older revision, and a merge migration joined it to dev's head (b4c7e8f1a2d3). That works alone, but once another migration PR lands the same way, dev has two Alembic heads and `alembic upgrade head` fails with "Multiple head revisions". Point the migration at dev's head and drop the merge migration. Also drop an extra blank line after the imports that ruff flags (I001).
…the user list sort index The previous migration PR in the series (PasarGuard#774) has landed, so point this migration at its revision (b7e2c4d91f60) to keep a single Alembic head.
…he subscription update index The previous migration PR in the series (PasarGuard#865) has landed, so point this migration at its revision (86f7c2a14d3e) to keep a single Alembic head.
* feat(nodes): persist node and core config order * fix(db): batch reorder updates for sqlite limits * fix(migrations): merge parallel heads * fix(dashboard): address reorder review findings * fix(nodes): limit reorder locks and payload size * docs: cover reorder migration and operation paths * fix(ordering): serialize sqlite writes * fix(ci): align reorder limits and finalmask test * fix(ordering): bound reorders to supported scope * fix(migrations): chain the node and core sort order migration onto the current head The migration branched off an older revision, and a merge migration joined it to dev's head (b4c7e8f1a2d3). That works alone, but once another migration PR lands the same way, dev has two Alembic heads and `alembic upgrade head` fails with "Multiple head revisions". Point the migration at dev's head and drop the merge migration. Both merge migrations (b7f4e6d9a1c2 and c12e9a875f04) only joined heads and carried no schema changes. * fix(migrations): chain the node and core sort order migration after the subscription update index The previous migration PR in the series (#865) has landed, so point this migration at its revision (86f7c2a14d3e) to keep a single Alembic head. --------- Co-authored-by: T3ST3ST3R0N <T3ST3ST3R0N@gmail.com>
… node and core sort order The other migration PRs in the series (PasarGuard#774, PasarGuard#865, PasarGuard#875) have landed, so point this migration at the latest revision (d73f8a2c4e91) to keep a single Alembic head.
* perf(groups): scale membership summaries * test: remove added PR tests * test: remove PR-specific changes to existing tests * fix(migrations): chain the group membership index migration onto the current head The migration branched off an older revision, and a merge migration joined it to dev's head (b4c7e8f1a2d3). That works alone, but once another migration PR lands the same way, dev has two Alembic heads and `alembic upgrade head` fails with "Multiple head revisions". Point the migration at dev's head and drop the merge migration. Also drop an extra blank line after the imports that ruff flags (I001). * refactor(groups): keep only the reverse membership indexes The member count rewrite overlaps #967, which counts members in SQL in load_group_attrs without loading them and keeps a fallback when the count was not loaded. Leave Group.total_users and get_group as on dev so this PR adds only the reverse membership indexes, which those group-centric counts and bulk membership deletes use. * fix(migrations): chain the group membership index migration after the node and core sort order The other migration PRs in the series (#774, #865, #875) have landed, so point this migration at the latest revision (d73f8a2c4e91) to keep a single Alembic head. --------- Co-authored-by: T3ST3ST3R0N <T3ST3ST3R0N@gmail.com>
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