Commit da088479 authored by Nick Thomas's avatar Nick Thomas

Remove tempfile from external diff creation

Since we already hold the diff in RAM, and this is a limited diff,
going to a temporary file is unnecessary and may introduce unexpected
latency in general.
parent d47ebd07
...@@ -487,8 +487,6 @@ class MergeRequestDiff < ApplicationRecord ...@@ -487,8 +487,6 @@ class MergeRequestDiff < ApplicationRecord
self.stored_externally = true self.stored_externally = true
rows rows
ensure
tempfile&.unlink
end end
def create_merge_request_diff_files(rows) def create_merge_request_diff_files(rows)
...@@ -499,17 +497,19 @@ class MergeRequestDiff < ApplicationRecord ...@@ -499,17 +497,19 @@ class MergeRequestDiff < ApplicationRecord
end end
def build_external_diff_tempfile(rows) def build_external_diff_tempfile(rows)
Tempfile.open(external_diff.filename) do |file| pos = 0
rows.each do |row|
data = row.delete(:diff)
row[:external_diff_offset] = file.pos
row[:external_diff_size] = data.bytesize
file.write(data) segments = rows.map do |row|
end segment = row.delete(:diff)
row[:external_diff_offset] = pos
row[:external_diff_size] = segment.bytesize
pos += segment.bytesize
file segment
end end
CarrierWaveStringFile.new(segments.join(''), external_diff.filename)
end end
def build_merge_request_diff_files(diffs) def build_merge_request_diff_files(diffs)
......
---
title: Remove tempfile from external diff creation
merge_request: 35750
author:
type: performance
# frozen_string_literal: true # frozen_string_literal: true
class CarrierWaveStringFile < StringIO class CarrierWaveStringFile < StringIO
def original_filename attr_reader :original_filename
""
def initialize(data, original_filename = "")
super(data)
@original_filename = original_filename
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