Commit 463d7aeb authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Reduce Markdown cache updates during deploy

Skips saving of Markdown cache if persisted data is newer than the
current version. This happens when some Markdown cache is generated on a
newer node that has the cache version incremented during a rolling
deploy or Canary deployment and then viewed again on an older node.

Changelog: performance
parent d0fe524e
......@@ -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