Lazy-load wiki sidebar from view templates
Summary
This is a follow-up to !32960 (comment 349399701).
Currently the data to render the wiki sidebar is loaded in a controller before_action
, which triggers calls to Gitaly.
This is wasteful because the sidebar is not actually rendered in many cases, e.g. when saving a page it's only needed if the action fails and we re-render the form.
Improvements
Refactor the controller code into helper methods, which get called from the views at the moment we're actually rendering the sidebar.
We could also introduce a WikiSidebarPresenter
and move things like WikiPage.group_by_directory
and Wiki#sidebar_entries
in there. But this might be overkill at the moment, as we'll probably rewrite the sidebar as a Vue component in the near future.
Involved components
-
app/controllers/concerns/wiki_actions.rb
(introduced in !32960 (merged)) app/helpers/wiki_helper.rb
app/views/projects/wikis/_sidebar.html.haml
Optional: Intended side effects
This should reduce the latency for most of the actions: https://dashboards.gitlab.net/d/rPsQXrImk/rails-controller?panelId=2&fullscreen&orgId=1&refresh=1m&var-env=gprd&var-type=web&var-stage=main&var-controller=Projects::WikisController&var-action=create&var-action=destroy&var-action=edit&var-action=new&var-action=preview_markdown.json&var-action=update
Optional: Missing test coverage
Instead of testing the assignments in the controller specs, we should verify the sidebar is rendered in the feature specs.