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