Commit 847ada36 authored by Valery Sizov's avatar Valery Sizov

Fix: Timeout creating and viewing merge request for binary file

parent 4646d453
---
title: Timeout creating and viewing merge request for binary file
merge_request:
author:
......@@ -20,7 +20,7 @@ module Gitlab
# Extracted method to highlight in the same iteration to the diff_collection.
def decorate_diff!(diff)
diff_file = super
cache_highlight!(diff_file) if cacheable?
cache_highlight!(diff_file) if cacheable?(diff_file)
diff_file
end
......@@ -60,8 +60,8 @@ module Gitlab
Rails.cache.write(cache_key, highlight_cache) if @highlight_cache_was_empty
end
def cacheable?
@merge_request_diff.present?
def cacheable?(diff_file)
@merge_request_diff.present? && diff_file.blob.text?
end
def cache_key
......
require 'spec_helper'
describe Gitlab::Diff::FileCollection::MergeRequestDiff do
let(:merge_request) { create :merge_request }
it 'does not hightlight binary files' do
allow_any_instance_of(Gitlab::Diff::File).to receive(:blob).and_return(double("text?" => false))
expect_any_instance_of(Gitlab::Diff::File).not_to receive(:highlighted_diff_lines)
described_class.new(merge_request.merge_request_diff, diff_options: nil).diff_files
end
end
......@@ -10,6 +10,7 @@ describe MergeRequests::MergeRequestDiffCacheService do
expect(Rails.cache).to receive(:read).with(cache_key).and_return({})
expect(Rails.cache).to receive(:write).with(cache_key, anything)
allow_any_instance_of(Gitlab::Diff::File).to receive(:blob).and_return(double("text?" => true))
subject.execute(merge_request)
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