Commit 746b6ec8 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'timeout-merge-request-for-binary-file' into 'master'

Fix: Timeout creating and viewing merge request for binary file

See merge request !7713
parents d03ca3d0 847ada36
---
title: Timeout creating and viewing merge request for binary file
merge_request:
author:
...@@ -20,7 +20,7 @@ module Gitlab ...@@ -20,7 +20,7 @@ module Gitlab
# Extracted method to highlight in the same iteration to the diff_collection. # Extracted method to highlight in the same iteration to the diff_collection.
def decorate_diff!(diff) def decorate_diff!(diff)
diff_file = super diff_file = super
cache_highlight!(diff_file) if cacheable? cache_highlight!(diff_file) if cacheable?(diff_file)
diff_file diff_file
end end
...@@ -60,8 +60,8 @@ module Gitlab ...@@ -60,8 +60,8 @@ module Gitlab
Rails.cache.write(cache_key, highlight_cache) if @highlight_cache_was_empty Rails.cache.write(cache_key, highlight_cache) if @highlight_cache_was_empty
end end
def cacheable? def cacheable?(diff_file)
@merge_request_diff.present? @merge_request_diff.present? && diff_file.blob.text?
end end
def cache_key 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 ...@@ -10,6 +10,7 @@ describe MergeRequests::MergeRequestDiffCacheService do
expect(Rails.cache).to receive(:read).with(cache_key).and_return({}) expect(Rails.cache).to receive(:read).with(cache_key).and_return({})
expect(Rails.cache).to receive(:write).with(cache_key, anything) 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) subject.execute(merge_request)
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