Commit 334adc45 authored by Sean McGivern's avatar Sean McGivern

Merge branch '262045-cached-markdown-blob' into 'master'

Cache markdown when viewing a blob

See merge request gitlab-org/gitlab!44300
parents dd79368b 8ec29b41
......@@ -9,5 +9,15 @@ module BlobViewer
self.extensions = Gitlab::MarkupHelper::EXTENSIONS
self.file_types = %i(readme)
self.binary = false
def banzai_render_context
{}.tap do |h|
h[:rendered] = blob.rendered_markup if blob.respond_to?(:rendered_markup)
if Feature.enabled?(:cached_markdown_blob, blob.project)
h[:cache_key] = ['blob', blob.id, 'commit', blob.commit_id]
end
end
end
end
end
- blob = viewer.blob
- context = blob.respond_to?(:rendered_markup) ? { rendered: blob.rendered_markup } : {}
.file-content.md
= markup(blob.name, blob.data, context)
= markup(blob.name, blob.data, viewer.banzai_render_context)
---
name: cached_markdown_blob
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44300
rollout_issue_url:
type: development
group: group::source code
default_enabled: false
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BlobViewer::Markup do
include FakeBlobHelpers
let(:project) { create(:project, :repository) }
let(:blob) { fake_blob(path: 'CHANGELOG.md') }
subject { described_class.new(blob) }
describe '#banzai_render_context' do
it 'returns context needed for banzai rendering' do
expect(subject.banzai_render_context.keys).to eq([:cache_key])
end
context 'when blob does respond to rendered_markup' do
before do
allow(blob).to receive(:rendered_markup).and_return("some rendered markup")
end
it 'does sets rendered key' do
expect(subject.banzai_render_context.keys).to include(:rendered)
end
end
context 'when cached_markdown_blob feature flag is disabled' do
before do
stub_feature_flags(cached_markdown_blob: false)
end
it 'does not set cache_key key' do
expect(subject.banzai_render_context.keys).not_to include(:cache_key)
end
end
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