Commit 43b812b8 authored by Igor Drozdov's avatar Igor Drozdov

Remove ReadmeBlob since it isn't used

ReadmeBlob#rendered_markup isn't called, but intended to be
called by BlobViewer::Markup. ReadmeBlob uses SimpleDelegator
to delegate all missing methods to Blob, but when the simple_viewer
call bubbles up to Blob#simple_viewer, the class isn't ReadmeBlob
anymore, but Blob, so it doesn't respond to rendered_markup.

ReadmeBlob was only responsible for calling
Repository#rendered_markup that cached the content in Redis.
Currently, we cache every blob content in Redis, so we can
remove ReadmeBlob instead of fixing the above problem.
parent 5fd14297
# frozen_string_literal: true
class ReadmeBlob < SimpleDelegator
include BlobActiveModel
attr_reader :repository
def initialize(blob, repository)
@repository = repository
super(blob)
end
def rendered_markup
repository.rendered_readme
end
end
...@@ -39,7 +39,7 @@ class Repository ...@@ -39,7 +39,7 @@ class Repository
# #
# For example, for entry `:commit_count` there's a method called `commit_count` which # For example, for entry `:commit_count` there's a method called `commit_count` which
# stores its data in the `commit_count` cache key. # stores its data in the `commit_count` cache key.
CACHED_METHODS = %i(size commit_count rendered_readme readme_path contribution_guide CACHED_METHODS = %i(size commit_count readme_path contribution_guide
changelog license_blob license_key gitignore changelog license_blob license_key gitignore
gitlab_ci_yml branch_names tag_names branch_count gitlab_ci_yml branch_names tag_names branch_count
tag_count avatar exists? root_ref merged_branch_names tag_count avatar exists? root_ref merged_branch_names
...@@ -53,7 +53,7 @@ class Repository ...@@ -53,7 +53,7 @@ class Repository
# changed. This Hash maps file types (as returned by Gitlab::FileDetector) to # changed. This Hash maps file types (as returned by Gitlab::FileDetector) to
# the corresponding methods to call for refreshing caches. # the corresponding methods to call for refreshing caches.
METHOD_CACHES_FOR_FILE_TYPES = { METHOD_CACHES_FOR_FILE_TYPES = {
readme: %i(rendered_readme readme_path), readme: %i(readme_path),
changelog: :changelog, changelog: :changelog,
license: %i(license_blob license_key license), license: %i(license_blob license_key license),
contributing: :contribution_guide, contributing: :contribution_guide,
...@@ -498,23 +498,7 @@ class Repository ...@@ -498,23 +498,7 @@ class Repository
end end
def blob_at(sha, path) def blob_at(sha, path)
blob = Blob.decorate(raw_repository.blob_at(sha, path), container) Blob.decorate(raw_repository.blob_at(sha, path), container)
# Don't attempt to return a special result if there is no blob at all
return unless blob
# Don't attempt to return a special result if this can't be a README
return blob unless Gitlab::FileDetector.type_of(blob.name) == :readme
# Don't attempt to return a special result unless we're looking at HEAD
return blob unless head_commit&.sha == sha
case path
when head_tree&.readme_path
ReadmeBlob.new(blob, self)
else
blob
end
rescue Gitlab::Git::Repository::NoRepository rescue Gitlab::Git::Repository::NoRepository
nil nil
end end
...@@ -612,15 +596,6 @@ class Repository ...@@ -612,15 +596,6 @@ class Repository
end end
cache_method :readme_path cache_method :readme_path
def rendered_readme
return unless readme
context = { project: project }
MarkupHelper.markup_unsafe(readme.name, readme.data, context)
end
cache_method :rendered_readme
def contribution_guide def contribution_guide
file_on_head(:contributing) file_on_head(:contributing)
end end
......
...@@ -292,12 +292,11 @@ RSpec.describe Gitlab::RepositoryCacheAdapter do ...@@ -292,12 +292,11 @@ RSpec.describe Gitlab::RepositoryCacheAdapter do
describe '#expire_method_caches' do describe '#expire_method_caches' do
it 'expires the caches of the given methods' do it 'expires the caches of the given methods' do
expect(cache).to receive(:expire).with(:rendered_readme)
expect(cache).to receive(:expire).with(:branch_names) expect(cache).to receive(:expire).with(:branch_names)
expect(redis_set_cache).to receive(:expire).with(:rendered_readme, :branch_names) expect(redis_set_cache).to receive(:expire).with(:branch_names)
expect(redis_hash_cache).to receive(:delete).with(:rendered_readme, :branch_names) expect(redis_hash_cache).to receive(:delete).with(:branch_names)
repository.expire_method_caches(%i(rendered_readme branch_names)) repository.expire_method_caches(%i(branch_names))
end end
it 'does not expire caches for non-existent methods' do it 'does not expire caches for non-existent methods' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ReadmeBlob do
include FakeBlobHelpers
describe 'policy' do
let(:project) { build(:project, :repository) }
subject { described_class.new(fake_blob(path: 'README.md'), project.repository) }
it 'works with policy' do
expect(Ability.allowed?(project.creator, :read_blob, subject)).to be_truthy
end
end
end
...@@ -483,12 +483,6 @@ RSpec.describe Repository do ...@@ -483,12 +483,6 @@ RSpec.describe Repository do
it { is_expected.to be_an_instance_of(::Blob) } it { is_expected.to be_an_instance_of(::Blob) }
end end
context 'readme blob on HEAD' do
subject { repository.blob_at(repository.head_commit.sha, 'README.md') }
it { is_expected.to be_an_instance_of(::ReadmeBlob) }
end
context 'readme blob not on HEAD' do context 'readme blob not on HEAD' do
subject { repository.blob_at(repository.find_branch('feature').target, 'README.md') } subject { repository.blob_at(repository.find_branch('feature').target, 'README.md') }
...@@ -1938,7 +1932,6 @@ RSpec.describe Repository do ...@@ -1938,7 +1932,6 @@ RSpec.describe Repository do
expect(repository).to receive(:expire_method_caches).with([ expect(repository).to receive(:expire_method_caches).with([
:size, :size,
:commit_count, :commit_count,
:rendered_readme,
:readme_path, :readme_path,
:contribution_guide, :contribution_guide,
:changelog, :changelog,
...@@ -2314,14 +2307,6 @@ RSpec.describe Repository do ...@@ -2314,14 +2307,6 @@ RSpec.describe Repository do
expect(repository.readme).to be_nil expect(repository.readme).to be_nil
end end
end end
context 'when a README exists' do
let(:project) { create(:project, :repository) }
it 'returns the README' do
expect(repository.readme).to be_an_instance_of(ReadmeBlob)
end
end
end end
end end
...@@ -2527,9 +2512,8 @@ RSpec.describe Repository do ...@@ -2527,9 +2512,8 @@ RSpec.describe Repository do
describe '#refresh_method_caches' do describe '#refresh_method_caches' do
it 'refreshes the caches of the given types' do it 'refreshes the caches of the given types' do
expect(repository).to receive(:expire_method_caches) expect(repository).to receive(:expire_method_caches)
.with(%i(rendered_readme readme_path license_blob license_key license)) .with(%i(readme_path license_blob license_key license))
expect(repository).to receive(:rendered_readme)
expect(repository).to receive(:readme_path) expect(repository).to receive(:readme_path)
expect(repository).to receive(:license_blob) expect(repository).to receive(:license_blob)
expect(repository).to receive(:license_key) expect(repository).to receive(:license_key)
......
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