From eea1b88547bb038b34b0691f0280d54d5dd23947 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Wed, 5 Sep 2018 23:05:09 +0100 Subject: [PATCH] Properly fix an introduced N+1 SQL issue loading commit authors --- app/controllers/projects/refs_controller.rb | 3 +++ app/models/commit.rb | 7 +------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb index 200054b4746..0fed7f6576c 100644 --- a/app/controllers/projects/refs_controller.rb +++ b/app/controllers/projects/refs_controller.rb @@ -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 diff --git a/app/models/commit.rb b/app/models/commit.rb index c993f3ed507..49c36ad9d3f 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -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