diff options
| author | Robert Speicher <robert@gitlab.com> | 2016-10-07 08:52:26 +0000 |
|---|---|---|
| committer | Robert Speicher <robert@gitlab.com> | 2016-10-07 08:52:26 +0000 |
| commit | a17412f0aa9ef9c99a5c136906ea8a585326c27d (patch) | |
| tree | 4e0d7171e0e9d6f57e151341d8b57328e4376ad1 /app/models/snippet.rb | |
| parent | c2cf1dd6c771ee3a181fa9704da593daa825c58a (diff) | |
| parent | 110e15da260f96baffb48bebb8cba796374fbb1e (diff) | |
| download | gitlab-ce-a17412f0aa9ef9c99a5c136906ea8a585326c27d.tar.gz | |
Merge branch '18337-cache-html-in-database' into 'master'
Cache rendered Markdown fields in the database
## What does this MR do?
Introduces cache fields for Markdown-containing fields in the database, and populates them.
## Why was this MR needed?
Rendering Markdown into HTML is performance-intensive. A Redis cache already exists, but this approach is expected to be more performant and reduce unnecessary cache invalidations.
## What are the relevant issue numbers?
Closes #18337
See merge request !6095
Diffstat (limited to 'app/models/snippet.rb')
| -rw-r--r-- | app/models/snippet.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 8a1730f3f36..2373b445009 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -1,11 +1,21 @@ class Snippet < ActiveRecord::Base include Gitlab::VisibilityLevel include Linguist::BlobHelper + include CacheMarkdownField include Participable include Referable include Sortable include Awardable + cache_markdown_field :title, pipeline: :single_line + cache_markdown_field :content + + # If file_name changes, it invalidates content + alias_method :default_content_html_invalidator, :content_html_invalidated? + def content_html_invalidated? + default_content_html_invalidator || file_name_changed? + end + default_value_for :visibility_level, Snippet::PRIVATE belongs_to :author, class_name: 'User' |
