Merge branch '58297-remove-extraneous-gitaly-calls-from-md-rendering' into 'master'

Remove extraneous DiffNote#supports_suggestion? calls

See merge request gitlab-org/gitlab-ce!29027
This commit is contained in:
Dmitriy Zaporozhets 2019-06-07 10:13:07 +00:00
commit 96e2ff69ac
6 changed files with 17 additions and 6 deletions

View File

@ -90,7 +90,7 @@ class DiffNote < Note
end
def banzai_render_context(field)
super.merge(project: project, suggestions_filter_enabled: supports_suggestion?)
super.merge(suggestions_filter_enabled: true)
end
private

View File

@ -38,7 +38,9 @@ class PreviewMarkdownService < BaseService
head_sha: params[:head_sha],
start_sha: params[:start_sha])
Gitlab::Diff::SuggestionsParser.parse(text, position: position, project: project)
Gitlab::Diff::SuggestionsParser.parse(text, position: position,
project: project,
supports_suggestion: params[:preview_suggestions])
end
def preview_sugestions?

View File

@ -0,0 +1,5 @@
---
title: Reduce Gitaly calls to improve performance when rendering suggestions
merge_request: 29027
author:
type: performance

View File

@ -10,10 +10,12 @@ module Gitlab
# Returns an array of Gitlab::Diff::Suggestion which represents each
# suggestion in the given text.
#
def parse(text, position:, project:)
def parse(text, position:, project:, supports_suggestion: true)
return [] unless position.complete?
html = Banzai.render(text, project: nil, no_original_data: true)
html = Banzai.render(text, project: nil,
no_original_data: true,
suggestions_filter_enabled: supports_suggestion)
doc = Nokogiri::HTML(html)
suggestion_nodes = doc.search('pre.suggestion')

View File

@ -56,7 +56,9 @@ describe PreviewMarkdownService do
expect(Gitlab::Diff::SuggestionsParser)
.to receive(:parse)
.with(text, position: position, project: merge_request.project)
.with(text, position: position,
project: merge_request.project,
supports_suggestion: true)
.and_call_original
result = service.execute

View File

@ -96,7 +96,7 @@ describe Suggestions::CreateService do
it 'creates no suggestion when diff file is not found' do
expect_next_instance_of(DiffNote) do |diff_note|
expect(diff_note).to receive(:latest_diff_file).twice { nil }
expect(diff_note).to receive(:latest_diff_file).once { nil }
end
expect { subject.execute }.not_to change(Suggestion, :count)