Update Note to load notes in the right order

This commit is contained in:
Riyad Preukschas 2012-09-13 15:43:16 +02:00
parent 8b6dba749a
commit 6ffec9a298
2 changed files with 13 additions and 12 deletions

View file

@ -8,24 +8,25 @@ module Notes
@notes = case target_type @notes = case target_type
when "commit" when "commit"
then project.commit_notes(project.commit(target_id)).fresh.limit(20) project.commit_notes(project.commit(target_id)).fresh.limit(20)
when "snippet"
then project.snippets.find(target_id).notes
when "wall"
then project.common_notes.order("created_at DESC").fresh.limit(50)
when "issue" when "issue"
then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) project.issues.find(target_id).notes.inc_author.fresh.limit(20)
when "merge_request" when "merge_request"
then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) project.merge_requests.find(target_id).notes.inc_author.fresh.limit(20)
when "snippet"
project.snippets.find(target_id).notes.fresh
when "wall"
# this is the only case, where the order is DESC
project.common_notes.order("created_at DESC").limit(50)
when "wiki" when "wiki"
then project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20]
end end
@notes = if last_id @notes = if last_id
@notes.where("id > ?", last_id) @notes.where("id < ?", last_id)
elsif first_id elsif first_id
@notes.where("id < ?", first_id) @notes.where("id > ?", first_id)
else else
@notes @notes
end end

View file

@ -36,7 +36,7 @@ class Note < ActiveRecord::Base
scope :today, where("created_at >= :date", date: Date.today) scope :today, where("created_at >= :date", date: Date.today)
scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
scope :since, lambda { |day| where("created_at >= :date", date: (day)) } scope :since, lambda { |day| where("created_at >= :date", date: (day)) }
scope :fresh, order("created_at DESC") scope :fresh, order("created_at ASC")
scope :inc_author_project, includes(:project, :author) scope :inc_author_project, includes(:project, :author)
scope :inc_author, includes(:author) scope :inc_author, includes(:author)