Commit ce4c38b3 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'debug-banzai-cache' into 'master'

Add DEBUG_BANZAI_CACHE env var to debug Banzai cache issue.

See https://gitlab.com/gitlab-org/gitlab-ce/issues/4130#note_3012511

See merge request !2283
parents e586492e 4b027bc9
module Banzai module Banzai
module Renderer module Renderer
CACHE_ENABLED = false
# Convert a Markdown String into an HTML-safe String of HTML # Convert a Markdown String into an HTML-safe String of HTML
# #
# Note that while the returned HTML will have been sanitized of dangerous # Note that while the returned HTML will have been sanitized of dangerous
...@@ -20,13 +18,22 @@ module Banzai ...@@ -20,13 +18,22 @@ module Banzai
cache_key = context.delete(:cache_key) cache_key = context.delete(:cache_key)
cache_key = full_cache_key(cache_key, context[:pipeline]) cache_key = full_cache_key(cache_key, context[:pipeline])
if cache_key && CACHE_ENABLED cacheless = cacheless_render(text, context)
Rails.cache.fetch(cache_key) do
cacheless_render(text, context) if cache_key && ENV["DEBUG_BANZAI_CACHE"]
cached = Rails.cache.fetch(cache_key) { cacheless }
if cached != cacheless
Rails.logger.warn "Banzai cache mismatch"
Rails.logger.warn "Text: #{text.inspect}"
Rails.logger.warn "Context: #{context.inspect}"
Rails.logger.warn "Cache key: #{cache_key.inspect}"
Rails.logger.warn "Cacheless: #{cacheless.inspect}"
Rails.logger.warn "With cache: #{cached.inspect}"
end end
else
cacheless_render(text, context)
end end
cacheless
end end
def self.render_result(text, context = {}) def self.render_result(text, context = {})
......
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