From 4768a1e26f70263be24ac681042507fe01218b9b Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Thu, 26 Oct 2017 11:33:54 +0100 Subject: [PATCH] Set merge_request_diff_id on MR when creating Once we migrate existing MRs to have this column, we will be able to get the latest diff for a single merge request more efficiently, and (more importantly) get all latest diffs for a collection of MRs efficiently. --- app/models/merge_request_diff.rb | 4 ++++ ...1-add-a-merge_request_diff_id-column-to-merge_requests.yml | 2 +- lib/gitlab/import_export/import_export.yml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index faf0b95f842..1eda0f9cbbd 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -48,6 +48,10 @@ class MergeRequestDiff < ActiveRecord::Base # Collect information about commits and diff from repository # and save it to the database as serialized data def save_git_content + MergeRequest + .where('id = ? AND COALESCE(latest_merge_request_diff_id, 0) < ?', self.merge_request_id, self.id) + .update_all(latest_merge_request_diff_id: self.id) + ensure_commit_shas save_commits save_diffs diff --git a/changelogs/unreleased/37631-add-a-merge_request_diff_id-column-to-merge_requests.yml b/changelogs/unreleased/37631-add-a-merge_request_diff_id-column-to-merge_requests.yml index 1a8632f7450..a7127f49c16 100644 --- a/changelogs/unreleased/37631-add-a-merge_request_diff_id-column-to-merge_requests.yml +++ b/changelogs/unreleased/37631-add-a-merge_request_diff_id-column-to-merge_requests.yml @@ -1,5 +1,5 @@ --- -title: Make finding most recent merge request diffs more efficient +title: Add a latest_merge_request_diff_id column to merge_requests merge_request: 15035 author: type: performance diff --git a/lib/gitlab/import_export/import_export.yml b/lib/gitlab/import_export/import_export.yml index 57678ffdd2a..26665d7d926 100644 --- a/lib/gitlab/import_export/import_export.yml +++ b/lib/gitlab/import_export/import_export.yml @@ -113,7 +113,7 @@ excluded_attributes: - :milestone_id - :ref_fetched - :merge_jid - - :merge_request_diff_id + - :latest_merge_request_diff_id award_emoji: - :awardable_id statuses: