@@ -404,11 +404,16 @@ export function partitionPullRequestsWithPriority<Entry extends PullRequestListE
404404 others . push ( entry ) ;
405405 }
406406 }
407- const byRecency = ( left : Entry , right : Entry ) => right . updatedAt . localeCompare ( left . updatedAt ) ;
408407 return (
409408 [
410- { key : "authored" , entries : [ ...authoredByKey . values ( ) ] . toSorted ( byRecency ) } ,
411- { key : "reviewRequested" , entries : [ ...reviewByKey . values ( ) ] . toSorted ( byRecency ) } ,
409+ {
410+ key : "authored" ,
411+ entries : [ ...authoredByKey . values ( ) ] . toSorted ( comparePullRequestsByRecency ) ,
412+ } ,
413+ {
414+ key : "reviewRequested" ,
415+ entries : [ ...reviewByKey . values ( ) ] . toSorted ( comparePullRequestsByRecency ) ,
416+ } ,
412417 { key : "others" , entries : others } ,
413418 ] as const
414419 )
@@ -503,7 +508,7 @@ export function mergePullRequestLists(
503508 return {
504509 viewers,
505510 providers : [ ...providers . values ( ) ] ,
506- entries : entries . toSorted ( ( left , right ) => right . updatedAt . localeCompare ( left . updatedAt ) ) ,
511+ entries : entries . toSorted ( comparePullRequestsByRecency ) ,
507512 errors,
508513 truncated,
509514 nextCursors,
@@ -697,7 +702,7 @@ export function rankPullRequestMatches<Entry extends PullRequestListEntry>(
697702 if ( query . trim ( ) . length === 0 ) return entries ;
698703 return entries . toSorted ( ( left , right ) => {
699704 const byScore = scorePullRequestMatch ( right , query ) - scorePullRequestMatch ( left , query ) ;
700- return byScore !== 0 ? byScore : right . updatedAt . localeCompare ( left . updatedAt ) ;
705+ return byScore !== 0 ? byScore : comparePullRequestsByRecency ( left , right ) ;
701706 } ) ;
702707}
703708
@@ -718,24 +723,26 @@ export function rankPullRequestsByMergeReadiness<Entry extends PullRequestListEn
718723 if ( byTier !== 0 ) return byTier ;
719724 const measured = Number ( hasMeasuredSize ( right ) ) - Number ( hasMeasuredSize ( left ) ) ;
720725 const sized = left . additions + left . deletions - ( right . additions + right . deletions ) ;
721- return measured || sized || right . updatedAt . localeCompare ( left . updatedAt ) ;
726+ return measured || sized || comparePullRequestsByRecency ( left , right ) ;
722727 } ) ;
723728}
724729
730+ function comparePullRequestsByRecency ( left : PullRequestListEntry , right : PullRequestListEntry ) {
731+ const leftUpdated = toSortableTimestamp ( left . updatedAt ) ;
732+ const rightUpdated = toSortableTimestamp ( right . updatedAt ) ;
733+ const measured = Number ( leftUpdated === null ) - Number ( rightUpdated === null ) ;
734+ if ( measured !== 0 ) return measured ;
735+ if ( leftUpdated === null || rightUpdated === null ) return 0 ;
736+ return rightUpdated - leftUpdated ;
737+ }
738+
725739function rankByTierThenRecency < Entry extends PullRequestListEntry > (
726740 entries : ReadonlyArray < Entry > ,
727741 tier : ( entry : Entry ) => number ,
728742) : ReadonlyArray < Entry > {
729- const timestamp = ( entry : Entry ) => toSortableTimestamp ( entry . updatedAt ) ;
730743 return entries . toSorted ( ( left , right ) => {
731744 const byTier = tier ( left ) - tier ( right ) ;
732- if ( byTier !== 0 ) return byTier ;
733- const leftUpdated = timestamp ( left ) ;
734- const rightUpdated = timestamp ( right ) ;
735- const measured = Number ( leftUpdated === null ) - Number ( rightUpdated === null ) ;
736- if ( measured !== 0 ) return measured ;
737- if ( leftUpdated === null || rightUpdated === null ) return 0 ;
738- return rightUpdated - leftUpdated ;
745+ return byTier !== 0 ? byTier : comparePullRequestsByRecency ( left , right ) ;
739746 } ) ;
740747}
741748
0 commit comments