Repository navigation
perf(groups): add reverse group membership indexes - #772
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
WalkthroughGroup summaries now populate ChangesGroup membership scaling
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant GroupListAPI
participant get_group
participant SQLDatabase
GroupListAPI->>get_group: Request group summaries
get_group->>SQLDatabase: Count user associations and fetch groups
SQLDatabase-->>get_group: Return groups with total_users
get_group-->>GroupListAPI: Return summaries without Group.users
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change preserves existing response behavior and includes regression coverage and migration validation; no actionable merge-blocking risk remains. Pre-merge checks |
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
c9fdd96 to
2759487
Compare
…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 member count rewrite overlaps PasarGuard#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.
… 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.
…ain bba95f274 Checked with git ls-remote on 2026-10-11 02:55 UTC. Panel dev moved from d94e157 to 83fe90e with 22 commits; main is still v5.4.1. - PasarGuard#879 (2d0ca81, loopback Xray client inbounds) is ported by design: the fork took the open pull request on 2026-09-25 as 2e7fc45 with migration bfd88026565b, the same listener rewrite. - PasarGuard#934 (a5b28f3) moves from the port queue to a dated waiver until 2026-11-09: the fork refuses to delete a core that nodes still use (W3-013, fix/node-health) instead of restarting those nodes. - PasarGuard#993 (Hysteria2 FinalMask without a udp mask) is queued until 2026-10-18: the fork has the same FinalMask | dict field and the same non-null-safe udpHop reads, so a udpHop-only host can fail the whole subscription. - PasarGuard#984, PasarGuard#985, PasarGuard#986, PasarGuard#989, PasarGuard#944, PasarGuard#864, PasarGuard#948, PasarGuard#951, PasarGuard#778, PasarGuard#774, PasarGuard#787, PasarGuard#994, PasarGuard#865, PasarGuard#875, PasarGuard#718, PasarGuard#967, PasarGuard#772, PasarGuard#662, PasarGuard#995 and PasarGuard#913 are queued as security: no until 2026-10-25, each with its reason; PasarGuard#913's node-removal half is already in the fork through sync_remove_users. - The branch commits that upstream squash-merged (the three dashboard branches, telegram/tests, fix/core-editor-api-section-followup, fix/hwid-count-test-cleanup, fix/hysteria-finalmask-quic-only) follow their squash, by patch-id or by an equal tree. Scripts main moved to bba95f274 (PasarGuard#35, PasarGuard#36, PasarGuard#37 after PasarGuard#34). The three squashes are queued security: no until 2026-10-25, and their pre-squash branch commits are waived as superseded (equal trees). Against live upstream the panel gate now fails only on the 17 port-queue commits classified security: yes, and the forks gate only on node f72ac0ef (security: yes). No upstream commit is undecided.
* 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 PasarGuard#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 (PasarGuard#774, PasarGuard#865, PasarGuard#875) have landed, so point this migration at the latest revision (d73f8a2c4e91) to keep a single Alembic head. --------- Co-authored-by: T3ST3ST3R0N <[email protected]> (cherry picked from commit 4008dcb) (cherry picked from commit 0e65172173a534529858bd1d4e47790d139d7155)
Summary
Group.total_usersin SQL for the group-list query instead of hydrating every relatedUserCloses #771
Type of change
Checklist
Testing
uv run ruff check .— passeduv run ruff format --check app/db/models.py app/db/crud/group.py tests/test_group_membership_indexes.py tests/api/test_group.py— passeduv run pytest -q tests/test_group_membership_indexes.py tests/api/test_group.py::test_groups_get_counts_users_without_loading_user_rows— 3 passeduv run alembic checkon SQLite — no new upgrade operationsCOMMIT,CREATE INDEX CONCURRENTLY, thenBEGIN; downgrade emitsDROP INDEX CONCURRENTLYSynthetic SQLite benchmark (500,000 memberships / 100 groups):
The benchmark is directional and is not presented as a production guarantee.
Screenshots
Not applicable (backend/database-only change).
Notes for reviewers
autocommit_block()for this path.Summary by CodeRabbit
Improvements
Bug Fixes
Tests