Add search for merge_user in merge request view and API
What does this MR do and why?
Implementation of #384574 (closed). This way it is possible to filter merged MRs by the person merging it. Also supports negation.
Screenshots or screen recordings
How to set up and validate locally
- Set-up a local instance
- chose any project, that has merged MRs (I tested with gitlab-org/gitlab-shell)
- execute searches
Changes affecting DB Queries
find user by name or id
The feature uses the already existing User.find_by_id
or User.find_by_username
. One of these is executed per request, to create a user object for searching.
-- find_by_username
SELECT
users.*
FROM
users
WHERE
lower( users.username ) IN ( lower( 'root' ) )
LIMIT 1;
https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/24906/commands/79094
-- find_by_id
SELECT
users.*
FROM
users
WHERE
users.id = 20
LIMIT 1;
Filter by existing user
The feature extends the existing queries for the merge_request dashboard by an additional feature. The main queries for the dashboard are extended by clauses for merge_request_metrics.merged_by_id
, everything else is pre-exiting. Resulting queries without additional filters are:
-- filter by existing user
SELECT
count(*) AS count_all,
merge_requests.state_id AS merge_requests_state_id
FROM
merge_requests
JOIN merge_request_metrics ON merge_request_metrics.merge_request_id = merge_requests.id
WHERE
merge_request_metrics.target_project_id = 3 AND
merge_request_metrics.merged_by_id = 20
GROUP BY
merge_requests.state_id;
https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/24990/commands/79396
SELECT
merge_requests.*
FROM
merge_requests
JOIN merge_request_metrics ON merge_request_metrics.merge_request_id = merge_requests.id
WHERE
merge_requests.state_id IN ( 3 ) AND
merge_request_metrics.target_project_id = 3 AND
merge_request_metrics.merged_by_id = 20
ORDER BY
merge_requests.created_at DESC,
merge_requests.id DESC
LIMIT 20
OFFSET 0;
https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/24990/commands/79397
Filter by non-existing user
-- filter by non-existing user
-- no query emmitted
-- no query emmitted
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.