Store MR ref_fetched status in the database
In order to make MRs created before 8.0 work, we create a hidden ref pointing to the HEAD of the MR, to ensure that it isn't GCed in future.
We do this in two steps:
- Check if the ref already exists in the repo.
- If it doesn't, create it.
Merge requests don't normally need to hit git, because we serialise content in the database. (https://gitlab.com/gitlab-org/gitlab-ce/issues/30224 will change this slightly - the commits tab will need to hit git, but everything else should still be DB-only.)
This is one place where we do hit git, however, and we do it every single time (for step 1), for every merge request, whether it was created before 8.0 or not. This can cause problems for very large repos with lots of MRs and corresponding refs: https://gitlab.slack.com/archives/C4N66DV1S/p1498032906974903
We can see that this is called a lot: https://performance.gitlab.net/dashboard/db/method-calls-by-action-and-worker?orgId=1&var-method=MergeRequest%23ref_fetched%3F
We could just add a column to the MR table, ref_fetched
, and set that to true once we've fetched the ref.