summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgitlabhq <m@gitlabhq.com>2011-11-15 04:09:07 -0500
committergitlabhq <m@gitlabhq.com>2011-11-15 04:09:07 -0500
commit6b9f221a278ebe4a78f4f0b4d60f87659785595c (patch)
tree88dde06b7be81b2de6d83f136644b5eb4885d0b5
parent762946995ea9d477f00fea19e5040bf4dd437cb9 (diff)
downloadgitlab-ce-6b9f221a278ebe4a78f4f0b4d60f87659785595c.tar.gz
perfomance fix
-rw-r--r--app/controllers/issues_controller.rb4
-rw-r--r--app/models/note.rb2
-rw-r--r--app/models/project.rb14
3 files changed, 16 insertions, 4 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 508cfc3974a..108577b9120 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -19,6 +19,8 @@ class IssuesController < ApplicationController
else @project.issues.opened
end
+ @issues = @issues.includes(:author, :project)
+
respond_to do |format|
format.html # index.html.erb
format.js
@@ -35,7 +37,7 @@ class IssuesController < ApplicationController
end
def show
- @notes = @issue.notes.order("created_at DESC").limit(20)
+ @notes = @issue.notes.inc_author.order("created_at DESC").limit(20)
@note = @project.notes.new(:noteable => @issue)
respond_to do |format|
diff --git a/app/models/note.rb b/app/models/note.rb
index c3c10639bf9..b256347abb1 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -30,6 +30,8 @@ class Note < ActiveRecord::Base
scope :last_week, where("created_at >= :date", :date => (Date.today - 7.days))
scope :since, lambda { |day| where("created_at >= :date", :date => (day)) }
scope :fresh, order("created_at DESC")
+ scope :inc_author_project, includes(:project, :author)
+ scope :inc_author, includes(:author)
mount_uploader :attachment, AttachmentUploader
end
diff --git a/app/models/project.rb b/app/models/project.rb
index e4448e786e9..474e42ed08e 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -74,8 +74,16 @@ class Project < ActiveRecord::Base
users_projects.find_by_user_id(user.id) if user
end
+ def fresh_issues(n)
+ issues.includes(:project, :author).order("created_at desc").first(n)
+ end
+
+ def fresh_notes(n)
+ notes.inc_author_project.order("created_at desc").first(n)
+ end
+
def common_notes
- notes.where(:noteable_type => ["", nil])
+ notes.where(:noteable_type => ["", nil]).inc_author_project
end
def build_commit_note(commit)
@@ -134,8 +142,8 @@ class Project < ActiveRecord::Base
def updates(n = 3)
[
fresh_commits(n),
- issues.last(n),
- notes.fresh.limit(n)
+ fresh_issues(n),
+ fresh_notes(n)
].compact.flatten.sort do |x, y|
y.created_at <=> x.created_at
end[0...n]