-
Notifications
You must be signed in to change notification settings - Fork 0
perf(rbac): optimize ExpireRoles command for production #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Remove declare(strict_types=1) for consistency - Implement batch processing (100 items/transaction) - Use cursor() for memory-efficient streaming - Delete-first-then-log pattern prevents race conditions - Add processChunk() helper for separation of concerns - Test coverage: 250 roles, chunk boundaries, concurrency Closes #119
💡 Tip: Consider Using Draft PRsBenefits of opening PRs as drafts initially:
How to convert:
This is just a friendly reminder - feel free to continue as is! 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the roles:expire command for better performance and concurrency handling when processing expired temporal role assignments. The optimization shifts from individual transactions per role to batch processing with chunking, implements a delete-first-then-log pattern to prevent duplicate audit logs, and uses cursor-based streaming for memory efficiency.
Key Changes:
- Refactored command to use cursor-based streaming and batch processing (100 items per chunk) instead of per-item transactions
- Implemented delete-first-then-log pattern to prevent duplicate audit logs during concurrent execution
- Added comprehensive test coverage for chunk boundaries (100, 101, 250 roles) and race condition scenarios
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| app/Console/Commands/ExpireRoles.php | Refactored to use cursor streaming and batch processing; extracted chunk processing logic into separate method; removed declare(strict_types=1) |
| tests/Feature/Console/ExpireRolesCommandTest.php | Added four new test cases covering large-scale processing, concurrent execution, and chunk boundary conditions |
| CHANGELOG.md | Documented the optimization changes and improvements |
- Extract CHUNK_SIZE constant (DRY principle) - Optimize test performance with factory()->count() - 18% faster test execution (7.83s -> 6.42s) All tests pass: 14 passed (46 assertions)
💡 Tip: Consider Using Draft PRsBenefits of opening PRs as drafts initially:
How to convert:
This is just a friendly reminder - feel free to continue as is! 😊 |
Summary
Optimizes the
ExpireRolescommand based on Copilot review feedback from PR #118, addressing performance, memory efficiency, and race condition concerns for production use.Related Issues
Closes #119
Changes
🎯 Code Style & Consistency
declare(strict_types=1)- Aligns with other console commands (GenerateTenantCommand,RotateDekCommand,RotateKekCommand)⚡ Performance Optimizations
cursor()instead ofget()for streaming results without loading all into memoryprocessChunk()helper method for cleaner code organization🔒 Race Condition Prevention
if ($deleted > 0))Testing
New Tests (5 added)
Quality Gates
Performance Impact
Before
get()loads all expired roles into memoryAfter
cursor()streams results (constant memory usage)Deployment Notes
No migration required. Command is backward compatible.
Checklist