Add bulk execution to seat type calculator
What does this MR do and why?
This code refactors a seat type calculator for GitLab subscriptions to improve performance and functionality. The main changes include:
Performance Improvements:
- Added a new
bulk_executemethod that can calculate seat types for multiple users at once, rather than processing them one by one - Added memoization to cache the subscription tier lookup, avoiding repeated database queries
- Moved user membership lookups to a more efficient batch operation
Code Structure Changes:
- Reorganized constants into frozen arrays for better maintainability
- Changed the constructor only to require the namespace parameter, with the user now passed to the execute methods
- Added proper error handling for cases where user memberships cannot be found
- Simplified the seat type calculation logic by removing intermediate methods
Functionality Updates:
- The calculator now handles both single-user (
execute) and multiple user (bulk_execute) scenarios - Improved validation with a specific error type for missing memberships
- Streamlined the tier determination logic (free, premium, ultimate)
These changes make the code more efficient when processing a large number of users simultaneously, which is crucial for organizations with hundreds of users, while maintaining the same core functionality of determining the type of subscription seat each user should be assigned.
References
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
Green test pipeline
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Lukas Wanko