Improve performance of `MemberRole.elevating`
We need to improve performance of elevating scope of MemberRole and the methods that use this scope.
Right now the query is under elevated_guests Feature Flag.
After fixing this we can remove the FF: #410805 (closed)
Cause of the problem
In !114734 (merged) we merged adding read_vulnerabilitypermission to Custom roles. This, however, caused a performance problem.
The problem was in the scope MemberRole.elevating and it caused a problem on the group members page (not loading for probably owners, 500 error). See gitlab-com/gl-infra/production#14234 (closed) for more details.
scope :elevating, -> do
return none if elevating_permissions.empty?
The scope itself was not changed, but it finally got elevationg_permissionsso the query was changed.
In elevating_permissions we have ALL_CUSTOMIZABLE_PERMISSIONS.keys - CUSTOMIZABLE_PERMISSIONS_EXEMPT_FROM_CONSUMING_SEAT and read_vulnerability is the first permission that is not exempt from consuming seat.
We fixed this in !120488 (merged) by moving the code under elevated_guests Feature Flag.