Skip to content

Use Redis for CacheMarkDownField on non AR models

Patrick Bajao requested to merge 54140-non-ar-cache-commit-markdown into master

What does this MR do?

Based from https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/23513 which is done by @reprazent. This MR merged the commit from that MR and fixes the conflicts and ensure it works with the recent state of GitLab Markdown.

This allows using CacheMarkdownField for models that are not backed by ActiveRecord.

When the including class inherits ActiveRecord::Base we include Gitlab::MarkdownCache::ActiveRecord::Extension. This will cause the markdown fields to be rendered and the generated HTML stored in a <field>_html attribute on the record. We also store the version used for generating the markdown.

All other classes that include this model will include the Gitlab::MarkdownCache::Redis::Extension. This add the <field>_html attributes to that model and will generate the html in them. The generated HTML will be cached in redis under the key markdown_cache:<cache_key>. The class this included in must therefore respond to cache_key.

Does this MR meet the acceptance criteria?

Conformity

Performance and testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Closes #54140 (closed)

Edited by Patrick Bajao

Merge request reports