Optimize merge request refresh by using the database to check commit SHAs
Previously for a given merge request, we would:
- Create the array of commit SHAs involved in the push (A)
- Request all merge request commits and map the SHA (B)
- Reload the diff if there were any common commits between A and B
We can avoid additional database querying and overhead by checking with the database whether the merge request contains any of the commit SHAs.
Relates to #53213
In #49703 (comment 113602024), we see that a push to the staging
www-gitlab-com resulted in 204 queries for
SELECT * FROM merge_request_diff_commits.