diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2017-11-06 16:52:56 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-11-06 16:52:56 +0000 |
commit | bf0331dc72db658b012d58e33ca47da6d8f99d46 (patch) | |
tree | f596c4876cd50bf13afd1f3e60ccd57640b61656 /lib/banzai/renderer.rb | |
parent | 34a205b308d80d600c5651cfb9694f978ef01cab (diff) | |
download | gitlab-ce-bf0331dc72db658b012d58e33ca47da6d8f99d46.tar.gz |
Resolve "DashboardController#activity.json is slow due to SQL"
Diffstat (limited to 'lib/banzai/renderer.rb')
-rw-r--r-- | lib/banzai/renderer.rb | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb index 5f91884a878..5cb9adf52b0 100644 --- a/lib/banzai/renderer.rb +++ b/lib/banzai/renderer.rb @@ -32,12 +32,9 @@ module Banzai # Convert a Markdown-containing field on an object into an HTML-safe String # of HTML. This method is analogous to calling render(object.field), but it # can cache the rendered HTML in the object, rather than Redis. - # - # The context to use is managed by the object and cannot be changed. - # Use #render, passing it the field text, if a custom rendering is needed. - def self.render_field(object, field) + def self.render_field(object, field, context = {}) unless object.respond_to?(:cached_markdown_fields) - return cacheless_render_field(object, field) + return cacheless_render_field(object, field, context) end object.refresh_markdown_cache! unless object.cached_html_up_to_date?(field) @@ -46,9 +43,9 @@ module Banzai end # Same as +render_field+, but without consulting or updating the cache field - def self.cacheless_render_field(object, field, options = {}) + def self.cacheless_render_field(object, field, context = {}) text = object.__send__(field) # rubocop:disable GitlabSecurity/PublicSend - context = object.banzai_render_context(field).merge(options) + context = context.reverse_merge(object.banzai_render_context(field)) if object.respond_to?(:banzai_render_context) cacheless_render(text, context) end |