Skip to content

Allow filtering of members by state in REST API

Vijay Hawoldar requested to merge vij-filter-members-by-state into master

What does this MR do and why?

We are in the progress of implementing a User Cap feature (&6862 (closed)) which will put Members (Project and Group) into a pending or awaiting state (customer facing we use pending, in code we use awaiting).

In order to support the management (approval) of these pending members, we need to be able to list them in the frontend.

To support this, this MR enables filtering of our existing members API endpoint by state

Notes

I tried out adding an index on state and source_id and although it improved the members query being used in the API endpoint, it seemed to slow down others like inserts, so I'm not sure it's really worth it.

Testing against the GitLab org in #database-lab:

without index with index
INSERT 14.73ms INSERT 204.426ms
SELECT 1.289s (cold cache) -
SELECT 3.056ms (warm cache) SELECT 2.403ms (warm cache)

Given these results, I think I'm leaning towards not adding an index right now - there's also an issue for adding one / improving overall query times here: #344660

How to set up and validate locally

  1. Make a group member pending/awaiting
    GroupMember.last.wait!
    => true
  2. Hit the API endpoint for that member's group/user with the appropriate state filter
    curl --request GET \
    --url http://127.0.0.1:3000/api/v4/groups/:group_id/members?state=awaiting \
    --header 'PRIVATE-TOKEN: <your token>' \

This can also be done for Projects, by swapping the appropriate sections in the path and using ProjectMember instead of GroupMember

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vijay Hawoldar

Merge request reports