Defer Banzai context member resolution until actually used by filters

What does this MR do and why?

CacheMarkdownField#banzai_render_context is called for every single Markdown field render in the site. This includes when the rendered HTML is cached in the database row for the field: we still need the render context, because every render must pass through the post-processing pipeline.

At the moment, this method always calls self.project, self.group if self responds to :group, same for self.author (notes in particular use this), and self.parent_user (only non-nil for snippets). For non-cached renders, these values are almost always all going to be used by the main pipeline they're rendered with. For cached renders, however — the majority of all renders — only the post-processing pipeline runs, and in many instances, the group, author and parent_user will never be consulted.

This is probably the hottest path that exists in the Markdown pipeline, and we might be able to make a noticeable dent on database read traffic by removing unnecessary lookups. This MR seeks to measure this dent by making these lookups lazy, conditional on a FF. If it's noticeable, it's worth!, and we should roll out the FF. If not, let's not complicate things for no gain.

References

See CacheMarkdownField.banzai_render_context forces... (#589496 - closed).

How to set up and validate locally

There is no user-visible change, so instead we seek to observe the difference before-and-after on queries made when rendering from cache.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Asherah Connor

Merge request reports

Loading