Skip to content
Snippets Groups Projects
Commit 6ffec9a2 authored by Riyad Preukschas's avatar Riyad Preukschas
Browse files

Update Note to load notes in the right order

parent 8b6dba74
No related branches found
No related tags found
1 merge request!1465Change comments order
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment