Commit 2c0a664a authored by Kerri Miller's avatar Kerri Miller

Allow diff_files to return undecorated files

parent 01e2177a
......@@ -16,13 +16,13 @@ module Gitlab
fallback_diff_refs: merge_request_diff.fallback_diff_refs)
end
def diff_files
strong_memoize(:diff_files) do
diff_files = super
diff_files.each { |diff_file| cache.decorate(diff_file) }
diff_files
def diff_files(decorate_diff_files: true)
if decorate_diff_files
decorated_diff_files
else
strong_memoize(:undecorated_diff_files) do
super()
end
end
end
......@@ -46,6 +46,16 @@ module Gitlab
private
def decorated_diff_files
strong_memoize(:diff_files) do
diff_files = diff_files(decorate_diff_files: false)
diff_files.each { |diff_file| cache.decorate(diff_file) }
diff_files
end
end
def cache
@cache ||= if Feature.enabled?(:hset_redis_diff_caching, project)
Gitlab::Diff::HighlightCache.new(self)
......
......@@ -68,12 +68,17 @@ module Gitlab
end
end
<<<<<<< HEAD
def cacheable_files
strong_memoize(:cacheable_files) do
diff_files = @diff_collection.diff_files
diff_files.select { |file| cacheable?(file) && read_file(file).nil? }
end
=======
def uncached_files
diff_files.select { |file| read_cache[file.file_path].nil? }
>>>>>>> Allow diff_files to return undecorated files
end
# Given a hash of:
......@@ -112,10 +117,9 @@ module Gitlab
deprecated_cache.clear
end
#
def file_paths
strong_memoize(:file_paths) do
@diff_collection.diffs.collect(&:file_path)
diff_files.collect(&:file_path)
end
end
......@@ -146,6 +150,12 @@ module Gitlab
def cacheable?(diff_file)
diffable.present? && diff_file.text? && diff_file.diffable?
end
def diff_files
strong_memoize(:diff_files) do
@diff_collection.diff_files(decorate_diff_files: true)
end
end
end
end
end
......@@ -9,6 +9,14 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
let(:diff_files) { subject.diff_files }
describe '#diff_files' do
context 'when decorate_diff_files is false' do
it 'should not attempt to decorate diff files' do
expect(subject.send(:cache)).not_to receive(:decorate)
subject.diff_files(decorate_diff_files: false)
end
end
it 'does not highlight binary files' do
allow_next_instance_of(Gitlab::Diff::File) do |instance|
allow(instance).to receive(:text?).and_return(false)
......
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