Commit e8ab4d92 authored by Greg Stark's avatar Greg Stark

Treat empty markdown and html strings as valid cached text, not missing cache...

Treat empty markdown and html strings as valid cached text, not missing cache that needs to be updated
parent be8ca260
......@@ -85,8 +85,7 @@ module CacheMarkdownField
def cached_html_up_to_date?(markdown_field)
html_field = cached_markdown_fields.html_field(markdown_field)
cached = cached_html_for(markdown_field).present? && __send__(markdown_field).present? # rubocop:disable GitlabSecurity/PublicSend
return false unless cached
return false if cached_html_for(markdown_field).nil? && !__send__(markdown_field).nil? # rubocop:disable GitlabSecurity/PublicSend
markdown_changed = attribute_changed?(markdown_field) || false
html_changed = attribute_changed?(html_field) || false
......
---
title: Treat empty markdown and html strings as valid cached text, not missing cache
that needs to be updated
merge_request:
author:
type: performance
......@@ -102,6 +102,26 @@ describe CacheMarkdownField do
it { expect(thing.cached_markdown_version).to eq(CacheMarkdownField::CACHE_VERSION) }
end
context 'when a markdown field is set repeatedly to an empty string' do
it do
expect(thing).to receive(:refresh_markdown_cache).once
thing.foo = ''
thing.save
thing.foo = ''
thing.save
end
end
context 'when a markdown field is set repeatedly to a string which renders as empty html' do
it do
expect(thing).to receive(:refresh_markdown_cache).once
thing.foo = '[//]: # (This is also a comment.)'
thing.save
thing.foo = '[//]: # (This is also a comment.)'
thing.save
end
end
context 'a non-markdown field changed' do
before do
thing.bar = 'OK'
......
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