Commit 6ffec9a298dd90275ec6b17d1e11554bd31b9f2c
1 parent
8b6dba74
Exists in
master
and in
4 other branches
Update Note to load notes in the right order
Showing
2 changed files
with
13 additions
and
12 deletions
Show diff stats
app/contexts/notes/load_context.rb
... | ... | @@ -8,24 +8,25 @@ module Notes |
8 | 8 | |
9 | 9 | |
10 | 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 | 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 | 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 | 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 | 24 | end |
24 | 25 | |
25 | 26 | @notes = if last_id |
26 | - @notes.where("id > ?", last_id) | |
27 | + @notes.where("id < ?", last_id) | |
27 | 28 | elsif first_id |
28 | - @notes.where("id < ?", first_id) | |
29 | + @notes.where("id > ?", first_id) | |
29 | 30 | else |
30 | 31 | @notes |
31 | 32 | end | ... | ... |
app/models/note.rb
... | ... | @@ -36,7 +36,7 @@ class Note < ActiveRecord::Base |
36 | 36 | scope :today, where("created_at >= :date", date: Date.today) |
37 | 37 | scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) |
38 | 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 | 40 | scope :inc_author_project, includes(:project, :author) |
41 | 41 | scope :inc_author, includes(:author) |
42 | 42 | ... | ... |