Commit 6ffec9a298dd90275ec6b17d1e11554bd31b9f2c

Authored by Riyad Preukschas
1 parent 8b6dba74

Update Note to load notes in the right order

app/contexts/notes/load_context.rb
@@ -8,24 +8,25 @@ module Notes @@ -8,24 +8,25 @@ module Notes
8 8
9 9
10 @notes = case target_type 10 @notes = case target_type
11 - when "commit"  
12 - then project.commit_notes(project.commit(target_id)).fresh.limit(20)  
13 - when "snippet"  
14 - then project.snippets.find(target_id).notes  
15 - when "wall"  
16 - then project.common_notes.order("created_at DESC").fresh.limit(50) 11 + when "commit"
  12 + project.commit_notes(project.commit(target_id)).fresh.limit(20)
17 when "issue" 13 when "issue"
18 - then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) 14 + project.issues.find(target_id).notes.inc_author.fresh.limit(20)
19 when "merge_request" 15 when "merge_request"
20 - then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) 16 + project.merge_requests.find(target_id).notes.inc_author.fresh.limit(20)
  17 + when "snippet"
  18 + project.snippets.find(target_id).notes.fresh
  19 + when "wall"
  20 + # this is the only case, where the order is DESC
  21 + project.common_notes.order("created_at DESC").limit(50)
21 when "wiki" 22 when "wiki"
22 - then project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] 23 + project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20]
23 end 24 end
24 25
25 @notes = if last_id 26 @notes = if last_id
26 - @notes.where("id > ?", last_id) 27 + @notes.where("id < ?", last_id)
27 elsif first_id 28 elsif first_id
28 - @notes.where("id < ?", first_id) 29 + @notes.where("id > ?", first_id)
29 else 30 else
30 @notes 31 @notes
31 end 32 end
app/models/note.rb
@@ -36,7 +36,7 @@ class Note &lt; ActiveRecord::Base @@ -36,7 +36,7 @@ class Note &lt; ActiveRecord::Base
36 scope :today, where("created_at >= :date", date: Date.today) 36 scope :today, where("created_at >= :date", date: Date.today)
37 scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) 37 scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
38 scope :since, lambda { |day| where("created_at >= :date", date: (day)) } 38 scope :since, lambda { |day| where("created_at >= :date", date: (day)) }
39 - scope :fresh, order("created_at DESC") 39 + scope :fresh, order("created_at ASC")
40 scope :inc_author_project, includes(:project, :author) 40 scope :inc_author_project, includes(:project, :author)
41 scope :inc_author, includes(:author) 41 scope :inc_author, includes(:author)
42 42