Skip to content

Commit

Permalink
Use outer join for issues ordering by milestones due.
Browse files Browse the repository at this point in the history
  • Loading branch information
tnir committed May 6, 2016
1 parent aa18cc2 commit 4ab49fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/concerns/issuable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ module Issuable
scope :only_opened, -> { with_state(:opened) }
scope :only_reopened, -> { with_state(:reopened) }
scope :closed, -> { with_state(:closed) }
scope :order_milestone_due_desc, -> { joins(:milestone).reorder('milestones.due_date DESC, milestones.id DESC') }
scope :order_milestone_due_asc, -> { joins(:milestone).reorder('milestones.due_date ASC, milestones.id ASC') }
scope :order_milestone_due_desc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date DESC, milestones.id DESC') }
scope :order_milestone_due_asc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date ASC, milestones.id ASC') }
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }

scope :join_project, -> { joins(:project) }
scope :references_project, -> { references(:project) }
scope :non_archived, -> { join_project.where(projects: { archived: false }) }
scope :outer_join_milestone, -> { joins("LEFT OUTER JOIN milestones ON milestones.id = #{table_name}.milestone_id") }

delegate :name,
:email,
Expand Down
2 changes: 2 additions & 0 deletions spec/features/issues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,14 @@
visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_soon)

expect(first_issue).to include('foo')
expect(last_issue).to include('baz')
end

it 'sorts by least recently due milestone' do
visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_later)

expect(first_issue).to include('bar')
expect(last_issue).to include('baz')
end
end

Expand Down

0 comments on commit 4ab49fa

Please sign in to comment.