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
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