Commit faacf3dd authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '36646-ignore-empty-diffs-for-external-diffs-migration' into 'master'

Ignore empty MR diffs when migrating to external storage

See merge request gitlab-org/gitlab!20296
parents 25df3e13 d8561f3a
......@@ -49,13 +49,14 @@ class MergeRequestDiff < ApplicationRecord
scope :by_commit_sha, ->(sha) do
joins(:merge_request_diff_commits).where(merge_request_diff_commits: { sha: sha }).reorder(nil)
end
scope :has_diff_files, -> { where(id: MergeRequestDiffFile.select(:merge_request_diff_id)) }
scope :by_project_id, -> (project_id) do
joins(:merge_request).where(merge_requests: { target_project_id: project_id })
end
scope :recent, -> { order(id: :desc).limit(100) }
scope :files_in_database, -> { where(stored_externally: [false, nil]) }
scope :files_in_database, -> { has_diff_files.where(stored_externally: [false, nil]) }
scope :not_latest_diffs, -> do
merge_requests = MergeRequest.arel_table
......
---
title: Ignore empty MR diffs when migrating to external storage
merge_request: 20296
author:
type: fixed
......@@ -98,6 +98,12 @@ describe MergeRequestDiff do
end
it { is_expected.to contain_exactly(outdated.id, latest.id, closed.id, merged.id, closed_recently.id, merged_recently.id) }
it 'ignores diffs with 0 files' do
MergeRequestDiffFile.where(merge_request_diff_id: [closed_recently.id, merged_recently.id]).delete_all
is_expected.to contain_exactly(outdated.id, latest.id, closed.id, merged.id)
end
end
context 'external diffs are enabled for outdated diffs' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment