Commit 83b1ad38 authored by Doug Stull's avatar Doug Stull

Merge branch '337291-prevent-markdown-cache-flipflop' into 'master'

Reduce Markdown cache updates during rolling deploy

See merge request gitlab-org/gitlab!67239
parents 73885b88 463d7aeb
......@@ -2,10 +2,14 @@
module Gitlab
module MarkdownCache
# Increment this number every time the renderer changes its output.
# Increment this number to invalidate cached HTML from Markdown documents.
# Even when reverting an MR, we should increment this because we only
# persist the cache when the new version is higher.
#
# Changing this value puts strain on the database, as every row with
# cached markdown needs to be updated. As a result, this line should
# not be changed.
# cached markdown needs to be updated. As a result, avoid changing
# this if the change to the renderer output is a new feature or a
# minor bug fix.
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/330313
CACHE_COMMONMARK_VERSION = 28
CACHE_COMMONMARK_VERSION_START = 10
......
......@@ -39,6 +39,7 @@ module Gitlab
def save_markdown(updates)
return unless persisted? && Gitlab::Database.read_write?
return if cached_markdown_version < cached_markdown_version_in_database
update_columns(updates)
end
......
......@@ -216,4 +216,16 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
end
end
end
context 'when persisted cache is newer than current version' do
before do
thing.update_column(:cached_markdown_version, thing.cached_markdown_version + 1)
end
it 'does not save the generated HTML' do
expect(thing).not_to receive(:update_columns)
thing.refresh_markdown_cache!
end
end
end
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