@@ -163,8 +163,13 @@ def most_recent
163
163
164
164
scope :not_authored_by , -> ( user ) { where . not ( author_id : user ) }
165
165
166
+ # N.B. The start_date and due_date columns are preserved on the issues table to enable performant sorting by these
167
+ # dates, since we would otherwise need to perform a join for the sort. These are synced via the DB trigger
168
+ # sync_issues_dates_with_work_item_dates_sources() from the work_item_dates_sources table
166
169
scope :order_due_date_asc , -> { reorder ( arel_table [ :due_date ] . asc . nulls_last ) }
167
170
scope :order_due_date_desc , -> { reorder ( arel_table [ :due_date ] . desc . nulls_last ) }
171
+ scope :order_start_date_asc , -> { reorder ( arel_table [ :start_date ] . asc . nulls_last ) }
172
+ scope :order_start_date_desc , -> { reorder ( arel_table [ :start_date ] . desc . nulls_last ) }
168
173
scope :order_closest_future_date , -> { reorder ( Arel . sql ( "CASE WHEN issues.due_date >= CURRENT_DATE THEN 0 ELSE 1 END ASC, ABS(CURRENT_DATE - issues.due_date) ASC" ) ) }
169
174
scope :order_created_at_desc , -> { reorder ( created_at : :desc ) }
170
175
scope :order_severity_asc , -> do
@@ -189,8 +194,6 @@ def most_recent
189
194
scope :order_escalation_status_desc , -> { includes ( :incident_management_issuable_escalation_status ) . order ( IncidentManagement ::IssuableEscalationStatus . arel_table [ :status ] . desc . nulls_last ) . references ( :incident_management_issuable_escalation_status ) }
190
195
scope :order_closed_at_asc , -> { reorder ( arel_table [ :closed_at ] . asc . nulls_last ) }
191
196
scope :order_closed_at_desc , -> { reorder ( arel_table [ :closed_at ] . desc . nulls_last ) }
192
- scope :order_start_date_asc , -> { left_joins ( :dates_source ) . order ( WorkItems ::DatesSource . arel_table [ :start_date ] . asc . nulls_last ) }
193
- scope :order_start_date_desc , -> { left_joins ( :dates_source ) . order ( WorkItems ::DatesSource . arel_table [ :start_date ] . desc . nulls_last ) }
194
197
195
198
scope :preload_associated_models , -> { preload ( :assignees , :labels , project : :namespace ) }
196
199
scope :with_web_entity_associations , -> do
@@ -449,15 +452,15 @@ def self.sort_by_attribute(method, excluded_labels: [])
449
452
when 'closest_future_date' , 'closest_future_date_asc' then order_closest_future_date
450
453
when 'due_date' , 'due_date_asc' then order_due_date_asc . with_order_id_desc
451
454
when 'due_date_desc' then order_due_date_desc . with_order_id_desc
455
+ when 'start_date' , 'start_date_asc' then order_start_date_asc . with_order_id_desc
456
+ when 'start_date_desc' then order_start_date_desc . with_order_id_desc
452
457
when 'relative_position' , 'relative_position_asc' then order_by_relative_position
453
458
when 'severity_asc' then order_severity_asc
454
459
when 'severity_desc' then order_severity_desc
455
460
when 'escalation_status_asc' then order_escalation_status_asc
456
461
when 'escalation_status_desc' then order_escalation_status_desc
457
462
when 'closed_at' , 'closed_at_asc' then order_closed_at_asc
458
463
when 'closed_at_desc' then order_closed_at_desc
459
- when 'start_date' , 'start_date_asc' then order_start_date_asc
460
- when 'start_date_desc' then order_start_date_desc
461
464
else
462
465
super
463
466
end
0 commit comments