diff options
author | Toon Claes <toon@gitlab.com> | 2017-04-06 16:47:52 +0200 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2017-04-27 13:22:17 +0200 |
commit | 05e0f504530a162d4bcb886adf504c12cffd5934 (patch) | |
tree | aeece92fb84421062c919e0c63173718db3577ba /app/models | |
parent | ef4d4446e957ecbb086859d96185a27af168d11c (diff) | |
download | gitlab-ce-05e0f504530a162d4bcb886adf504c12cffd5934.tar.gz |
Cache the rendered README, but post-process on show
Because the post-processing of the rendered README is dependent on the
context (i.e. the current user), do the post-processing when the
README is being displayed.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/repository.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 7bb874d7744..328e817cc3f 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,6 +1,7 @@ require 'securerandom' class Repository + include MarkupHelper include Gitlab::ShellAdapter include RepositoryMirroring @@ -17,9 +18,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 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 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 @@ -28,7 +29,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, @@ -527,7 +528,11 @@ class Repository head.readme end end - cache_method :readme + + def rendered_readme + markup_render(readme.name, readme.data) if readme + end + cache_method :rendered_readme def contribution_guide file_on_head(:contributing) |