summaryrefslogtreecommitdiff
path: root/app/services/notes
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-04-03 15:45:17 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2018-04-11 14:10:19 +0200
commitdaad7144ec7c0173439eeadd61590442e40a6051 (patch)
tree80a738c17196d0235cbc4c5589d6b04f96688b5c /app/services/notes
parent23fb465c75d00fd7156a540b7421a79e22df3966 (diff)
downloadgitlab-ce-daad7144ec7c0173439eeadd61590442e40a6051.tar.gz
Support Markdown rendering using multiple projectsrendering-markdown-multiple-projects
This refactors the Markdown pipeline so it supports the rendering of multiple documents that may belong to different projects. An example of where this happens is when displaying the event feed of a group. In this case we retrieve events for all projects in the group. Previously we would group events per project and render these chunks separately, but this would result in many SQL queries being executed. By extending the Markdown pipeline to support this out of the box we can drastically reduce the number of SQL queries. To achieve this we introduce a new object to the pipeline: Banzai::RenderContext. This object simply wraps two other objects: an optional Project instance, and an optional User instance. On its own this wouldn't be very helpful, but a RenderContext can also be used to associate HTML documents with specific Project instances. This work is done in Banzai::ObjectRenderer and allows us to reuse as many queries (and results) as possible.
Diffstat (limited to 'app/services/notes')
-rw-r--r--app/services/notes/render_service.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/app/services/notes/render_service.rb b/app/services/notes/render_service.rb
index a77e98c2b07..efc9d6da2aa 100644
--- a/app/services/notes/render_service.rb
+++ b/app/services/notes/render_service.rb
@@ -3,19 +3,18 @@ module Notes
# Renders a collection of Note instances.
#
# notes - The notes to render.
- # project - The project to use for redacting.
- # user - The user viewing the notes.
-
+ #
# Possible options:
+ #
# requested_path - The request path.
# project_wiki - The project's wiki.
# ref - The current Git reference.
# only_path - flag to turn relative paths into absolute ones.
# xhtml - flag to save the html in XHTML
- def execute(notes, project, **opts)
- renderer = Banzai::ObjectRenderer.new(project, current_user, **opts)
-
- renderer.render(notes, :note)
+ def execute(notes, options = {})
+ Banzai::ObjectRenderer
+ .new(user: current_user, redaction_context: options)
+ .render(notes, :note)
end
end
end