diff options
author | Toon Claes <toon@gitlab.com> | 2017-04-03 14:34:09 +0200 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2017-04-03 14:34:09 +0200 |
commit | 9422cd2b69a7504b96a60017139018396b40ba69 (patch) | |
tree | 000268e0aa7809bc341f9f66d080cfe6396ee01f | |
parent | 3b0116d87d7b2879ef501bc19d54d1b37ffe3b96 (diff) | |
download | gitlab-ce-tc-remove-readme-view-caching.tar.gz |
Cache prerendered README and postprocess on showtc-remove-readme-view-caching
-rw-r--r-- | app/helpers/markup_helper.rb | 14 | ||||
-rw-r--r-- | app/helpers/tree_helper.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 15 | ||||
-rw-r--r-- | app/views/projects/_readme.html.haml | 3 | ||||
-rw-r--r-- | app/views/projects/tree/_readme.html.haml | 2 | ||||
-rw-r--r-- | changelogs/unreleased/26585-remove-readme-view-caching.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/asciidoc.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/other_markup.rb | 9 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 4 |
9 files changed, 34 insertions, 30 deletions
diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index a80d914355c..35d5b5dc118 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -113,6 +113,11 @@ module MarkupHelper end def render_markup(file_name, file_content) + html = prerender_markup(file_name, file_content) + postprocess_markup(html) + end + + def prerender_markup(file_name, file_content) if gitlab_markdown?(file_name) Hamlit::RailsHelpers.preserve(markdown(file_content)) elsif asciidoc?(file_name) @@ -226,4 +231,13 @@ module MarkupHelper Banzai.post_process(html, context) end + + def postprocess_markup(html, context = {}) + html = banzai_post_process(html, context) + + filter = Banzai::Filter::SanitizationFilter.new(html) + html = filter.call.to_s + + html.html_safe + end end diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 4a76c679bad..7991a4873ee 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -12,10 +12,6 @@ module TreeHelper tree.html_safe end - def render_readme(readme) - render_markup(readme.name, readme.data) - end - # Return an image icon depending on the file type and mode # # type - String type of the tree item; either 'folder' or 'file' diff --git a/app/models/repository.rb b/app/models/repository.rb index 6ab04440ca8..3da96c19557 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,6 +1,7 @@ require 'securerandom' class Repository + include MarkupHelper include Gitlab::ShellAdapter attr_accessor :path_with_namespace, :project @@ -14,9 +15,9 @@ class Repository # same name. The cache key used by those methods must also match method's # name. # - # For example, for entry `:readme` there's a method called `readme` which - # stores its data in the `readme` cache key. - CACHED_METHODS = %i(size commit_count readme version contribution_guide + # For example, for entry `:commit_count` there's a method called `commit_count` which + # stores its data in the `commit_count` cache key. + CACHED_METHODS = %i(size commit_count rendered_readme version contribution_guide changelog license_blob license_key gitignore koding_yml gitlab_ci_yml branch_names tag_names branch_count tag_count avatar exists? empty? root_ref).freeze @@ -25,7 +26,7 @@ class Repository # changed. This Hash maps file types (as returned by Gitlab::FileDetector) to # the corresponding methods to call for refreshing caches. METHOD_CACHES_FOR_FILE_TYPES = { - readme: :readme, + readme: :rendered_readme, changelog: :changelog, license: %i(license_blob license_key), contributing: :contribution_guide, @@ -538,7 +539,11 @@ class Repository head.readme end end - cache_method :readme + + def rendered_readme + prerender_markup(readme.name, readme.data, postprocess: false) if readme + end + cache_method :rendered_readme def version file_on_head(:version) diff --git a/app/views/projects/_readme.html.haml b/app/views/projects/_readme.html.haml index b6fb08b68e9..9a79343396c 100644 --- a/app/views/projects/_readme.html.haml +++ b/app/views/projects/_readme.html.haml @@ -4,8 +4,7 @@ - if can?(current_user, :push_code, @project) = link_to icon('pencil'), namespace_project_edit_blob_path(@project.namespace, @project, tree_join(@repository.root_ref, readme.name)), class: 'light edit-project-readme' .file-content.wiki - = cache(readme_cache_key) do - = render_readme(readme) + = postprocess_markup(@repository.rendered_readme) - else .row-content-block.second-block.center %h3.page-title diff --git a/app/views/projects/tree/_readme.html.haml b/app/views/projects/tree/_readme.html.haml index bdcc160a067..30df6fd50d0 100644 --- a/app/views/projects/tree/_readme.html.haml +++ b/app/views/projects/tree/_readme.html.haml @@ -5,4 +5,4 @@ %strong = readme.name .file-content.wiki - = render_readme(readme) + = render_markup(readme.name, readme.data) diff --git a/changelogs/unreleased/26585-remove-readme-view-caching.yml b/changelogs/unreleased/26585-remove-readme-view-caching.yml new file mode 100644 index 00000000000..6aefae982bf --- /dev/null +++ b/changelogs/unreleased/26585-remove-readme-view-caching.yml @@ -0,0 +1,4 @@ +--- +title: 'Remove view fragment caching for project READMEs' +merge_request: 8838 +author: diff --git a/lib/gitlab/asciidoc.rb b/lib/gitlab/asciidoc.rb index d575367d81a..a68f4243239 100644 --- a/lib/gitlab/asciidoc.rb +++ b/lib/gitlab/asciidoc.rb @@ -32,14 +32,7 @@ module Gitlab plantuml_setup - html = ::Asciidoctor.convert(input, asciidoc_opts) - - html = Banzai.post_process(html, context) - - filter = Banzai::Filter::SanitizationFilter.new(html) - html = filter.call.to_s - - html.html_safe + ::Asciidoctor.convert(input, asciidoc_opts) end def self.plantuml_setup diff --git a/lib/gitlab/other_markup.rb b/lib/gitlab/other_markup.rb index e67acf28c94..408c9a80aa6 100644 --- a/lib/gitlab/other_markup.rb +++ b/lib/gitlab/other_markup.rb @@ -12,15 +12,8 @@ module Gitlab # :ref # def self.render(file_name, input, context) - html = GitHub::Markup.render(file_name, input). + GitHub::Markup.render(file_name, input). force_encoding(input.encoding) - - html = Banzai.post_process(html, context) - - filter = Banzai::Filter::SanitizationFilter.new(html) - html = filter.call.to_s - - html.html_safe end end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 585b87b828d..c707e9a0087 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1806,9 +1806,9 @@ describe Repository, models: true do describe '#refresh_method_caches' do it 'refreshes the caches of the given types' do expect(repository).to receive(:expire_method_caches). - with(%i(readme license_blob license_key)) + with(%i(rendered_readme license_blob license_key)) - expect(repository).to receive(:readme) + expect(repository).to receive(:rendered_readme) expect(repository).to receive(:license_blob) expect(repository).to receive(:license_key) |