Commit 9cdc774c authored by Pavel Shutsin's avatar Pavel Shutsin Committed by Adam Hegyi

Improve merge_request graphql endpoint

Fallback to denormalized metrics values if available
instead of calling for gitaly
parent 8f56e12b
......@@ -44,6 +44,7 @@ module ResolvesMergeRequests
author: [:author],
merged_at: [:metrics],
commit_count: [:metrics],
diff_stats_summary: [:metrics],
approved_by: [:approved_by_users],
milestone: [:milestone],
head_pipeline: [:merge_request_diff, { head_pipeline: [:merge_request] }]
......
......@@ -170,6 +170,12 @@ module Types
end
def diff_stats_summary
metrics = object.metrics
if metrics && metrics.added_lines && metrics.removed_lines
return { additions: metrics.added_lines, deletions: metrics.removed_lines, file_count: object.merge_request_diff&.files_count || 0 }
end
nil_stats = { additions: 0, deletions: 0, file_count: 0 }
return nil_stats unless object.diff_stats.present?
......
---
title: Optionally use merge request metrics association for merge request diff stats
in GraphQL
merge_request: 44613
author:
type: performance
......@@ -38,4 +38,40 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
expect(described_class).to have_graphql_fields(*expected_fields)
end
describe '#diff_stats_summary' do
subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json }
let(:current_user) { create :admin }
let(:query) do
%(
{
project(fullPath: "#{project.full_path}") {
mergeRequests {
nodes {
diffStatsSummary {
additions, deletions
}
}
}
}
}
)
end
let(:project) { create(:project, :public) }
let(:merge_request) { create(:merge_request, target_project: project, source_project: project) }
let(:response) { subject.dig('data', 'project', 'mergeRequests', 'nodes').first['diffStatsSummary'] }
context 'when MR metrics has additions and deletions' do
before do
merge_request.metrics.update!(added_lines: 5, removed_lines: 8)
end
it 'pulls out data from metrics object' do
expect(response).to match('additions' => 5, 'deletions' => 8)
end
end
end
end
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