diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb index 12856191c26..038645aa497 100644 --- a/app/controllers/projects/commits_controller.rb +++ b/app/controllers/projects/commits_controller.rb @@ -13,6 +13,8 @@ class Projects::CommitsController < Projects::ApplicationController @limit, @offset = (params[:limit] || 40), (params[:offset] || 0) @commits = @repo.commits(@ref, @path, @limit, @offset) + @note_counts = Note.where(commit_id: @commits.map(&:id)). + group(:commit_id).count respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 1abedc1f272..89f4ab01a3f 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -32,6 +32,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController end def show + @note_counts = Note.where(commit_id: @merge_request.commits.map(&:id)). + group(:commit_id).count respond_to do |format| format.html format.diff { render text: @merge_request.to_diff(current_user) } @@ -86,6 +88,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController @compare_failed = true end + @note_counts = Note.where(commit_id: @commits.map(&:id)). + group(:commit_id).count + @diffs = compare_action.diffs @merge_request.title = @merge_request.source_branch.titleize.humanize @target_project = @merge_request.target_project diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index a0606662807..74146b5f196 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -9,11 +9,15 @@ = link_to "Browse Code ยป", project_tree_path(project, commit), class: "pull-right" .notes_count - - notes = project.notes.for_commit_id(commit.id) - - if notes.any? + - if @note_counts + - note_count = @note_counts.fetch(commit.id, 0) + - else + - notes = project.notes.for_commit_id(commit.id) + - note_count = notes.count + + - if note_count > 0 %span.label.label-gray - %i.icon-comment - = notes.count + %i.icon-comment= note_count - if commit.description? .commit-row-description.js-toggle-content