GraphQL API: add endpoint to return a list open merge requests

What does this MR do and why?

Contributes to #499245 (closed)

Problem

We want to display opened merge requests that changed a particular path in the repository.

Solution

  • Add an argument blob_path to mergeRequests GraphQL query.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Database query

SELECT
    "merge_requests".*
FROM
    "merge_requests"
    INNER JOIN "merge_request_diffs" ON "merge_request_diffs"."id" = "merge_requests"."latest_merge_request_diff_id"
    INNER JOIN "merge_request_diff_files" ON "merge_request_diff_files"."merge_request_diff_id" = "merge_request_diffs"."id"
WHERE
    "merge_requests"."target_project_id" = 278964
    AND "merge_requests"."state_id" = 1
    AND "merge_requests"."target_branch" = 'master'
    AND "merge_requests"."created_at" >= '2024-11-06 00:00:00'
    AND "merge_request_diff_files"."old_path" = 'Gemfile'
ORDER BY
    "merge_requests"."created_at" DESC,
    "merge_requests"."id" DESC
LIMIT 6;
Time: 2.099 s
  - planning: 15.063 ms
  - execution: 2.084 s
    - I/O read: 2.019 s
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 1925 (~15.00 MiB) from the buffer pool
  - reads: 2106 (~16.50 MiB) from the OS file cache, including disk I/O
  - dirtied: 512 (~4.00 MiB)
  - writes: 0

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/34231/commands/105386

Note I spent some time to optimize the query and improve the performance. I could a reduction of the time by adding extra constraints to limit the potential number of returned merge requests. I think it should work better for regular project with not as many merge requests as https://gitlab.com/gitlab-org/gitlab/ has. I'm open to any suggestions that can improve the performance even further.

How to set up and validate locally

{
  project(fullPath: "gitlab-org/gitlab-test") {
    id
    mergeRequests(state: opened, targetBranches: "master", blobPath: "Gemfile", first: 5) {
      nodes {
        iid
      }
    }
  }
}

Numbered steps to set up and validate the change are strongly suggested.

Edited by Vasilii Iakliushin

Merge request reports

Loading