Repository navigation
perf(users): avoid materializing reset history in lists - #850
ImMohammad20000 merged 3 commits into
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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 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: Team Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. WalkthroughThe user list query now conditionally loads usage history and can aggregate lifetime traffic from reset logs. The web operation selects aggregation without loading history. Regression tests and a benchmark cover query results, relationship loading, and resource usage. ChangesUser usage aggregation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The dashboard user list now calculates lifetime traffic in SQL without loading reset-history rows, preserving reported totals while reducing resource use. The change is ready to merge. Sequence Diagram(s)sequenceDiagram
participant UserOperation
participant CRUD_get_users
participant UserUsageResetLogs
UserOperation->>CRUD_get_users: Set load_usage_logs=False
UserOperation->>CRUD_get_users: Set load_lifetime_used_traffic=True
CRUD_get_users->>UserUsageResetLogs: Sum used_traffic_at_reset by user
UserUsageResetLogs-->>CRUD_get_users: Return lifetime traffic totals
CRUD_get_users-->>UserOperation: Return users without usage_logs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
user_usage_logsrowBenchmark
Command:
python -m scripts.benchmark_user_list_usageEnvironment: Windows, Python 3.14, in-memory SQLite; 50 users with 1,000 reset-history rows each; median of 5 warmed runs. Peak memory is measured in a separate
tracemallocrun.The response still returns the exact same
lifetime_used_trafficvalues, including users with no reset history.Tests
python -m pytest tests/test_user_list_usage_aggregate.py -q(2 passed)python -m pytest tests --ignore=tests/api --ignore=tests/test_review_admins_unit.py -q(165 passed, 2 skipped)ruff check app/db/crud/user.py app/operation/user.py tests/test_user_list_usage_aggregate.py scripts/benchmark_user_list_usage.pyruff format --check app/db/crud/user.py app/operation/user.py tests/test_user_list_usage_aggregate.py scripts/benchmark_user_list_usage.pySummary by CodeRabbit
Performance
Bug Fixes
Tests