Repository navigation
perf(templates): avoid loading group members and batch list relations - #944
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⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. WalkthroughUser template creation and modification fetch associated groups without loading users or inbounds. User template retrieval eagerly loads groups and no longer runs a separate attribute-loading loop. ChangesUser template group loading
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Refactor Suggested reviewers: Merge Risk: ⚪ Minimal · up to Template responses retain their group IDs, and no merge-blocking issue was identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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. A rabbit checks the template rows, Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
82c6954 to
683d55c
Compare
…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.
…PasarGuard#944) Conflict in app/db/crud/user_template.py get_user_templates: kept the fork's truthy ids filter because upstream 0fa51f4 (empty id filter matches nothing) is ported in a later wave; took only the selectinload batching. (cherry picked from commit c600c6a)
Summary
Creating or updating a user template currently loads every user and inbound in its selected groups, although only the group association is needed. Listing templates also loads groups once per template. Disable those unnecessary group relationship loads on create/update and use
selectinload(UserTemplate.groups)for lists, preserving responses, filters, and pagination.Measured improvement
Local before/after comparison against
devat26047f6b, using the actual CRUD implementations on Python 3.14 / SQLite in memory:Timing uses five alternating measurements per implementation after one warmup each, with a fresh session per call and response validation included. Memory was measured separately with
tracemalloc; it is not process RSS. These are local synthetic CRUD measurements, not end-to-end API latency or a production guarantee. Larger lists use SQLAlchemy's select-in batches.Type of change
Checklist
app/db/crud/user_template.pychanges.Testing
pytest tests/api/test_user_template.py -q --tb=short: 16 passed, with bothDATABASE_URLandSQLALCHEMY_DATABASE_URLpointing to the same isolated temporary SQLite database.ruff check --no-fix app/db/crud/user_template.py,ruff format --check app/db/crud/user_template.py, andgit diff --check: passed.ruff check --no-fix .reports seven pre-existing issues in unchanged files; the modified file is clean.Screenshots
Not applicable.
Notes for reviewers
The existing group validation and authorization paths remain intact. PR #785 adds template ownership and does not implement this loading optimization; PR #772 optimizes group summaries rather than template CRUD. This PR targets
dev, asnextreferenced in CONTRIBUTING no longer exists.Summary by CodeRabbit