perf(users): avoid full-table sorts in list queries - #774
Conversation
|
@coderabbitai review |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
WalkthroughUser listing now uses deterministic sorting and narrow filtered count queries. The database schema adds a ChangesUser list query scaling
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change optimizes user-list counting and pagination while preserving the API contract; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Poem
🚥 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. Comment |
✅ Action performedReview finished.
|
Summary
/api/userstotal-count queryidtie-breaker for deterministic offset pagination(created_at, id)for the dashboard's default user-list orderCloses #773
Type of change
Checklist
Testing
uv run ruff check .— passeduv run pytest -q tests/test_user_list_query_scaling.py— 4 passeduv run pytest -q tests/api/test_user.py— 82 passeduv run alembic checkon SQLite — no new upgrade operationsCREATE INDEX CONCURRENTLY/DROP INDEX CONCURRENTLYSynthetic SQLite benchmark with 500,000 users and a 50-row page:
Before the change both plans used a full scan and temporary B-tree sort. The optimized page uses
idx_users_created_at_id; the count no longer sorts. The benchmark is directional, not a production guarantee.Screenshots
Not applicable (backend/database-only change).
Notes for reviewers
autocommit_block().devmigration head. If one lands first, the other migration should be rebased onto the new head before merge to avoid parallel Alembic heads.Summary by CodeRabbit
Performance
Bug Fixes