Don't do a commit lookup to present the MR entity, just return the sha

The MergeRequestWidgetEntity is used a lot in AJAX requests, and shaving
that git operation will hopefully translate in a performance improvement
This commit is contained in:
Alejandro Rodríguez 2018-03-06 22:34:46 -03:00
parent bc365bd15a
commit c277aac9dc
2 changed files with 3 additions and 5 deletions

View file

@ -38,7 +38,7 @@ class MergeRequestWidgetEntity < IssuableEntity
# Diff sha's # Diff sha's
expose :diff_head_sha do |merge_request| expose :diff_head_sha do |merge_request|
merge_request.diff_head_sha if merge_request.diff_head_commit merge_request.diff_head_sha.presence
end end
expose :merge_commit_message expose :merge_commit_message

View file

@ -147,9 +147,9 @@ describe MergeRequestWidgetEntity do
allow(resource).to receive(:diff_head_sha) { 'sha' } allow(resource).to receive(:diff_head_sha) { 'sha' }
end end
context 'when no diff head commit' do context 'when diff head commit is empty' do
it 'returns nil' do it 'returns nil' do
allow(resource).to receive(:diff_head_commit) { nil } allow(resource).to receive(:diff_head_sha) { '' }
expect(subject[:diff_head_sha]).to be_nil expect(subject[:diff_head_sha]).to be_nil
end end
@ -157,8 +157,6 @@ describe MergeRequestWidgetEntity do
context 'when diff head commit present' do context 'when diff head commit present' do
it 'returns diff head commit short id' do it 'returns diff head commit short id' do
allow(resource).to receive(:diff_head_commit) { double }
expect(subject[:diff_head_sha]).to eq('sha') expect(subject[:diff_head_sha]).to eq('sha')
end end
end end