Commit 6b9f221a278ebe4a78f4f0b4d60f87659785595c
1 parent
76294699
Exists in
master
and in
4 other branches
perfomance fix
Showing
3 changed files
with
16 additions
and
4 deletions
Show diff stats
app/controllers/issues_controller.rb
@@ -19,6 +19,8 @@ class IssuesController < ApplicationController | @@ -19,6 +19,8 @@ class IssuesController < ApplicationController | ||
19 | else @project.issues.opened | 19 | else @project.issues.opened |
20 | end | 20 | end |
21 | 21 | ||
22 | + @issues = @issues.includes(:author, :project) | ||
23 | + | ||
22 | respond_to do |format| | 24 | respond_to do |format| |
23 | format.html # index.html.erb | 25 | format.html # index.html.erb |
24 | format.js | 26 | format.js |
@@ -35,7 +37,7 @@ class IssuesController < ApplicationController | @@ -35,7 +37,7 @@ class IssuesController < ApplicationController | ||
35 | end | 37 | end |
36 | 38 | ||
37 | def show | 39 | def show |
38 | - @notes = @issue.notes.order("created_at DESC").limit(20) | 40 | + @notes = @issue.notes.inc_author.order("created_at DESC").limit(20) |
39 | @note = @project.notes.new(:noteable => @issue) | 41 | @note = @project.notes.new(:noteable => @issue) |
40 | 42 | ||
41 | respond_to do |format| | 43 | respond_to do |format| |
app/models/note.rb
@@ -30,6 +30,8 @@ class Note < ActiveRecord::Base | @@ -30,6 +30,8 @@ class Note < ActiveRecord::Base | ||
30 | scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days)) | 30 | scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days)) |
31 | scope :since, lambda { |day| where("created_at >= :date", :date => (day)) } | 31 | scope :since, lambda { |day| where("created_at >= :date", :date => (day)) } |
32 | scope :fresh, order("created_at DESC") | 32 | scope :fresh, order("created_at DESC") |
33 | + scope :inc_author_project, includes(:project, :author) | ||
34 | + scope :inc_author, includes(:author) | ||
33 | 35 | ||
34 | mount_uploader :attachment, AttachmentUploader | 36 | mount_uploader :attachment, AttachmentUploader |
35 | end | 37 | end |
app/models/project.rb
@@ -74,8 +74,16 @@ class Project < ActiveRecord::Base | @@ -74,8 +74,16 @@ class Project < ActiveRecord::Base | ||
74 | users_projects.find_by_user_id(user.id) if user | 74 | users_projects.find_by_user_id(user.id) if user |
75 | end | 75 | end |
76 | 76 | ||
77 | + def fresh_issues(n) | ||
78 | + issues.includes(:project, :author).order("created_at desc").first(n) | ||
79 | + end | ||
80 | + | ||
81 | + def fresh_notes(n) | ||
82 | + notes.inc_author_project.order("created_at desc").first(n) | ||
83 | + end | ||
84 | + | ||
77 | def common_notes | 85 | def common_notes |
78 | - notes.where(:noteable_type => ["", nil]) | 86 | + notes.where(:noteable_type => ["", nil]).inc_author_project |
79 | end | 87 | end |
80 | 88 | ||
81 | def build_commit_note(commit) | 89 | def build_commit_note(commit) |
@@ -134,8 +142,8 @@ class Project < ActiveRecord::Base | @@ -134,8 +142,8 @@ class Project < ActiveRecord::Base | ||
134 | def updates(n = 3) | 142 | def updates(n = 3) |
135 | [ | 143 | [ |
136 | fresh_commits(n), | 144 | fresh_commits(n), |
137 | - issues.last(n), | ||
138 | - notes.fresh.limit(n) | 145 | + fresh_issues(n), |
146 | + fresh_notes(n) | ||
139 | ].compact.flatten.sort do |x, y| | 147 | ].compact.flatten.sort do |x, y| |
140 | y.created_at <=> x.created_at | 148 | y.created_at <=> x.created_at |
141 | end[0...n] | 149 | end[0...n] |