Update Note to load notes in the right order
This commit is contained in:
parent
8b6dba749a
commit
6ffec9a298
|
@ -8,24 +8,25 @@ module Notes
|
|||
|
||||
|
||||
@notes = case target_type
|
||||
when "commit"
|
||||
then 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 "commit"
|
||||
project.commit_notes(project.commit(target_id)).fresh.limit(20)
|
||||
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"
|
||||
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"
|
||||
then project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20]
|
||||
project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20]
|
||||
end
|
||||
|
||||
@notes = if last_id
|
||||
@notes.where("id > ?", last_id)
|
||||
@notes.where("id < ?", last_id)
|
||||
elsif first_id
|
||||
@notes.where("id < ?", first_id)
|
||||
@notes.where("id > ?", first_id)
|
||||
else
|
||||
@notes
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ class Note < ActiveRecord::Base
|
|||
scope :today, where("created_at >= :date", date: Date.today)
|
||||
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 :fresh, order("created_at ASC")
|
||||
scope :inc_author_project, includes(:project, :author)
|
||||
scope :inc_author, includes(:author)
|
||||
|
||||
|
|
Loading…
Reference in a new issue