Commit f727d518 authored by Matthias Käppler's avatar Matthias Käppler Committed by Bob Van Landuyt

Improve diff_files endpoint performance

parent e70d6aa7
......@@ -33,7 +33,7 @@ if (filesContainer.length) {
axios
.get(batchPath)
.then(({ data }) => {
filesContainer.html($(data.html));
filesContainer.html($(data));
syntaxHighlight(filesContainer);
handleLocationHash();
new Diff();
......
......@@ -49,7 +49,7 @@ class Projects::CommitController < Projects::ApplicationController
end
def diff_files
render json: { html: view_to_html_string('projects/commit/diff_files', diffs: @diffs, environment: @environment) }
render template: 'projects/commit/diff_files', layout: false, locals: { diffs: @diffs, environment: @environment }
end
# rubocop: disable CodeReuse/ActiveRecord
......
---
title: Improve diff_files endpoint performance
merge_request: 59489
author:
type: performance
......@@ -3,6 +3,8 @@
module Gitlab
module Diff
class Highlight
PREFIX_REGEXP = /\A(.)/.freeze
attr_reader :diff_file, :diff_lines, :repository, :project
delegate :old_path, :new_path, :old_sha, :new_sha, to: :diff_file, prefix: :diff
......@@ -97,12 +99,12 @@ module Gitlab
rich_line = syntax_highlighter(diff_line).highlight(
diff_line.text(prefix: false),
context: { line_number: diff_line.line }
)&.html_safe
)
# Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content.
if rich_line
line_prefix = diff_line.text =~ /\A(.)/ ? Regexp.last_match(1) : ' '
line_prefix = diff_line.text =~ PREFIX_REGEXP ? Regexp.last_match(1) : ' '
rich_line.prepend(line_prefix).concat("\n")
end
end
......@@ -131,7 +133,7 @@ module Gitlab
# Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content.
if rich_line
line_prefix = diff_line.text =~ /\A(.)/ ? Regexp.last_match(1) : ' '
line_prefix = diff_line.text =~ PREFIX_REGEXP ? Regexp.last_match(1) : ' '
"#{line_prefix}#{rich_line}".html_safe
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