Commit 63b58b9491badf4fe5fa79a32c6ad77be2bf3c25
1 parent
75fbdc40
Exists in
master
and in
4 other branches
Reducing database access.
Showing
2 changed files
with
11 additions
and
3 deletions
Show diff stats
app/helpers/graph_helper.rb
@@ -4,8 +4,7 @@ module GraphHelper | @@ -4,8 +4,7 @@ module GraphHelper | ||
4 | refs += commit.refs.collect{|r|r.name}.join(" ") if commit.refs | 4 | refs += commit.refs.collect{|r|r.name}.join(" ") if commit.refs |
5 | 5 | ||
6 | # append note count | 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 | refs | 9 | refs |
11 | end | 10 | end |
app/models/network/graph.rb
@@ -2,7 +2,7 @@ require "grit" | @@ -2,7 +2,7 @@ require "grit" | ||
2 | 2 | ||
3 | module Network | 3 | module Network |
4 | class Graph | 4 | class Graph |
5 | - attr_reader :days, :commits, :map | 5 | + attr_reader :days, :commits, :map, :notes |
6 | 6 | ||
7 | def self.max_count | 7 | def self.max_count |
8 | @max_count ||= 650 | 8 | @max_count ||= 650 |
@@ -16,10 +16,19 @@ module Network | @@ -16,10 +16,19 @@ module Network | ||
16 | 16 | ||
17 | @commits = collect_commits | 17 | @commits = collect_commits |
18 | @days = index_commits | 18 | @days = index_commits |
19 | + @notes = collect_notes | ||
19 | end | 20 | end |
20 | 21 | ||
21 | protected | 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 | # Get commits from repository | 32 | # Get commits from repository |
24 | # | 33 | # |
25 | def collect_commits | 34 | def collect_commits |