Commit 6ffec9a2 authored by Riyad Preukschas's avatar Riyad Preukschas

Update Note to load notes in the right order

parent 8b6dba74
...@@ -8,24 +8,25 @@ module Notes ...@@ -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
......
...@@ -36,7 +36,7 @@ class Note < ActiveRecord::Base ...@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment