summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Stark <stark@gitlab.com>2017-12-08 17:54:18 +0000
committerGreg Stark <stark@gitlab.com>2017-12-11 12:04:06 +0000
commit9154aa05ed1e40bcf2c9510b05dd47a15029a8fb (patch)
treee9db2d90af07298905b89db6a41f6a6a8872b9f3
parentbe8ca260dadae948d09a87664baed8c85d133434 (diff)
downloadgitlab-ce-optimize-issues-avoid-noop-empty-cache-updates.tar.gz
Empty markdown was correctly cached as empty html but then treated asoptimize-issues-avoid-noop-empty-cache-updates
if it was always out of date and always refreshed.
-rw-r--r--app/models/concerns/cache_markdown_field.rb6
-rw-r--r--spec/models/concerns/cache_markdown_field_spec.rb19
2 files changed, 23 insertions, 2 deletions
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb
index 98776eab424..a3a385825b7 100644
--- a/app/models/concerns/cache_markdown_field.rb
+++ b/app/models/concerns/cache_markdown_field.rb
@@ -85,8 +85,10 @@ 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
+ original = __send__(markdown_field) # rubocop:disable GitlabSecurity/PublicSend
+ cached = cached_html_for(markdown_field)
+ return true if original.blank? && cached.blank?
+ return false unless original.present? && cached.present?
markdown_changed = attribute_changed?(markdown_field) || false
html_changed = attribute_changed?(html_field) || false
diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb
index 129dfa07f15..12e568f2008 100644
--- a/spec/models/concerns/cache_markdown_field_spec.rb
+++ b/spec/models/concerns/cache_markdown_field_spec.rb
@@ -171,6 +171,25 @@ describe CacheMarkdownField do
is_expected.to be_truthy
end
+ it 'returns true if markdown and html are both empty' do
+ thing.foo = ''
+ thing.foo_html = ''
+
+ is_expected.to be_truthy
+ end
+
+ it 'returns false if markdown is empty but html is not' do
+ thing.foo = ''
+
+ is_expected.to be_falsey
+ end
+
+ it 'returns false if html is empty but markdown is not' do
+ thing.foo_html = ''
+
+ is_expected.to be_falsey
+ end
+
it 'returns false if the markdown field is set but the html is not' do
thing.foo_html = nil