Commit d8561f3a authored by Nick Thomas's avatar Nick Thomas

Ignore empty MR diffs when migrating to external storage

parent 523e0b19
...@@ -49,13 +49,14 @@ class MergeRequestDiff < ApplicationRecord ...@@ -49,13 +49,14 @@ class MergeRequestDiff < ApplicationRecord
scope :by_commit_sha, ->(sha) do scope :by_commit_sha, ->(sha) do
joins(:merge_request_diff_commits).where(merge_request_diff_commits: { sha: sha }).reorder(nil) joins(:merge_request_diff_commits).where(merge_request_diff_commits: { sha: sha }).reorder(nil)
end end
scope :has_diff_files, -> { where(id: MergeRequestDiffFile.select(:merge_request_diff_id)) }
scope :by_project_id, -> (project_id) do scope :by_project_id, -> (project_id) do
joins(:merge_request).where(merge_requests: { target_project_id: project_id }) joins(:merge_request).where(merge_requests: { target_project_id: project_id })
end end
scope :recent, -> { order(id: :desc).limit(100) } 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 scope :not_latest_diffs, -> do
merge_requests = MergeRequest.arel_table 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 ...@@ -98,6 +98,12 @@ describe MergeRequestDiff do
end end
it { is_expected.to contain_exactly(outdated.id, latest.id, closed.id, merged.id, closed_recently.id, merged_recently.id) } 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 end
context 'external diffs are enabled for outdated diffs' do 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