Properly fix an introduced N+1 SQL issue loading commit authors

This commit is contained in:
Nick Thomas 2018-09-05 23:05:09 +01:00
parent 43859f59ae
commit eea1b88547
No known key found for this signature in database
GPG key ID: 2A313A47AFADACE9
2 changed files with 4 additions and 6 deletions

View file

@ -70,6 +70,9 @@ class Projects::RefsController < Projects::ApplicationController
end
def prerender_commit_full_titles!(commits)
# Preload commit authors as they are used in rendering
commits.each(&:lazy_author)
renderer = Banzai::ObjectRenderer.new(user: current_user, default_project: @project)
renderer.render(commits, :full_title)
end

View file

@ -39,12 +39,7 @@ class Commit
def banzai_render_context(field)
pipeline = field == :description ? :commit_description : :single_line
context = { pipeline: pipeline, project: self.project }
# The author is only needed when rendering the description
if field == :description
author = self.author
context[:author] = author if author
end
context[:author] = self.author if self.author
context
end