perfomance fix
This commit is contained in:
parent
762946995e
commit
6b9f221a27
3 changed files with 16 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue