Add member filter for user type
What does this MR do and why?
Describe in detail what your merge request does and why.
Adds ability to filter group members by user type.
Related to #338354 (closed)
The groups controller now accepts a user_type
param, such as https://gitlab.example.com/groups/flightjs/-/group_members?user_type=service_account
. This query would allow a group owner to filter by the specified user type. Similarly, this then adds the filtering ability to the group member finder.
This is the backend component to the frontend which is handled as part of !113884 (merged)
Database
Formatted query with user_type filter
SELECT members.* FROM ( SELECT DISTINCT ON ( user_id, invite_email ) * FROM members WHERE members.type = 'GroupMember' AND members.source_type = 'Namespace' AND members.requested_at IS NULL AND members.source_id IN ( SELECT namespaces.id FROM ( SELECT namespaces.* FROM namespaces WHERE namespaces.type = 'Group' AND namespaces.id = 634 ) AS namespaces WHERE namespaces.type = 'Group' ) AND members.access_level > 5 ORDER BY user_id, invite_email, access_level DESC, expires_at DESC, created_at ASC ) AS members LEFT JOIN users ON users.id = members.user_id WHERE members.type = 'GroupMember' AND users.user_type = 13;
Execution plan
Nested Loop (cost=9.00..12.05 rows=1 width=188) (actual time=3.879..3.881 rows=0 loops=1) Buffers: shared hit=12 read=4 I/O Timings: read=3.794 write=0.000 -> Subquery Scan on members (cost=8.44..8.46 rows=1 width=188) (actual time=3.878..3.880 rows=0 loops=1) Filter: ((members.type)::text = 'GroupMember'::text) Rows Removed by Filter: 0 Buffers: shared hit=12 read=4 I/O Timings: read=3.794 write=0.000 -> Unique (cost=8.44..8.45 rows=1 width=188) (actual time=3.878..3.879 rows=0 loops=1) Buffers: shared hit=12 read=4 I/O Timings: read=3.794 write=0.000 -> Sort (cost=8.44..8.44 rows=1 width=188) (actual time=3.877..3.878 rows=0 loops=1) Sort Key: members_1.user_id, members_1.invite_email, members_1.access_level DESC, members_1.expires_at DESC, members_1.created_at Sort Method: quicksort Memory: 25kB Buffers: shared hit=12 read=4 I/O Timings: read=3.794 write=0.000 -> Nested Loop Semi Join (cost=1.13..8.43 rows=1 width=188) (actual time=3.826..3.826 rows=0 loops=1) Buffers: shared read=4 I/O Timings: read=3.794 write=0.000 -> Index Scan using index_members_on_source_id_and_source_type on public.members members_1 (cost=0.56..4.83 rows=1 width=188) (actual time=3.825..3.825 rows=0 loops=1) Index Cond: ((members_1.source_id = 634) AND ((members_1.source_type)::text = 'Namespace'::text)) Filter: ((members_1.requested_at IS NULL) AND (members_1.access_level > 5) AND ((members_1.type)::text = 'GroupMember'::text)) Rows Removed by Filter: 0 Buffers: shared read=4 I/O Timings: read=3.794 write=0.000 -> Index Scan using namespaces_pkey on public.namespaces (cost=0.56..3.58 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=0) Index Cond: (namespaces.id = 634) Filter: ((namespaces.type)::text = 'Group'::text) Rows Removed by Filter: 0 I/O Timings: read=0.000 write=0.000 -> Index Only Scan using index_users_on_user_type_and_id on public.users (cost=0.56..3.58 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=0) Index Cond: (users.user_type = 13) Heap Fetches: 0 I/O Timings: read=0.000 write=0.000
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.