Add RecalculateProjectService for project_authorizations
What does this MR do and why?
Adds Authz::ProjectAuthorizations::RecalculateProjectService, which recalculates one project's project_authorizations for every user (https://gitlab.com/groups/gitlab-org/-/work_items/24326).
- It calculates every user's level with
EffectiveAccessLevelFinder, waits for any writer of those users or of the stored ones, then reads the stored rows again. It keeps only the users whose rows are wrong, including users who lost all access. - It writes those users through
WriteBatchService, one chunk at a time. Each chunk loads the project again and calculates withEffectiveAccessLevelPerUserFinder, so a move or share change after the comparison is seen. - An optional runtime limiter stops it between chunks. The payload's
completeis false when it stopped early.
Nothing calls it yet, so there is no behavior change.
Chunk size
The issue suggests 1,000 users per chunk, because the per-user finder's cost is mostly planning, which it pays on every call. WriteBatchService calculates and writes at most 100 IDs per transaction, which we kept until the table swap, so this uses its BATCH_SIZE. Calculating 1,000 users at once while writing them in 100-pair statements would need a change to WriteBatchService, which could be a follow-up.
References
- Closes https://gitlab.com/gitlab-org/gitlab/-/work_items/637572
WriteBatchService: !268492 (merged)- Proof of concept: !266827
Database
No new queries. It uses the existing finders, ProjectAuthorization.stored_levels_for_project without a user list (every user, as reviewed in !266833 (merged)), and WriteBatchService.
How to set up and validate locally
Not applicable, nothing calls the service yet. The spec covers it.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.