Commit 63b58b9491badf4fe5fa79a32c6ad77be2bf3c25

Authored by Sato Hiroyuki
1 parent 75fbdc40

Reducing database access.

app/helpers/graph_helper.rb
... ... @@ -4,8 +4,7 @@ module GraphHelper
4 4 refs += commit.refs.collect{|r|r.name}.join(" ") if commit.refs
5 5  
6 6 # append note count
7   - notes = @project.notes.for_commit_id(commit.id)
8   - refs += "[#{notes.count}]" if notes.any?
  7 + refs += "[#{@graph.notes[commit.id]}]" if @graph.notes[commit.id] > 0
9 8  
10 9 refs
11 10 end
... ...
app/models/network/graph.rb
... ... @@ -2,7 +2,7 @@ require "grit"
2 2  
3 3 module Network
4 4 class Graph
5   - attr_reader :days, :commits, :map
  5 + attr_reader :days, :commits, :map, :notes
6 6  
7 7 def self.max_count
8 8 @max_count ||= 650
... ... @@ -16,10 +16,19 @@ module Network
16 16  
17 17 @commits = collect_commits
18 18 @days = index_commits
  19 + @notes = collect_notes
19 20 end
20 21  
21 22 protected
22 23  
  24 + def collect_notes
  25 + h = Hash.new(0)
  26 + @project.notes.where('noteable_type = ?' ,"Commit").group('notes.commit_id').select('notes.commit_id, count(notes.id) as note_count').each do |item|
  27 + h[item["commit_id"]] = item["note_count"]
  28 + end
  29 + h
  30 + end
  31 +
23 32 # Get commits from repository
24 33 #
25 34 def collect_commits
... ...