@@ -469,11 +469,16 @@ export function partitionPullRequestsWithPriority<Entry extends PullRequestListE
469469 others . push ( entry ) ;
470470 }
471471 }
472- const byRecency = ( left : Entry , right : Entry ) => right . updatedAt . localeCompare ( left . updatedAt ) ;
473472 return (
474473 [
475- { key : "authored" , entries : [ ...authoredByKey . values ( ) ] . toSorted ( byRecency ) } ,
476- { key : "reviewRequested" , entries : [ ...reviewByKey . values ( ) ] . toSorted ( byRecency ) } ,
474+ {
475+ key : "authored" ,
476+ entries : [ ...authoredByKey . values ( ) ] . toSorted ( comparePullRequestsByRecency ) ,
477+ } ,
478+ {
479+ key : "reviewRequested" ,
480+ entries : [ ...reviewByKey . values ( ) ] . toSorted ( comparePullRequestsByRecency ) ,
481+ } ,
477482 { key : "others" , entries : others } ,
478483 ] as const
479484 )
@@ -564,7 +569,7 @@ export function mergePullRequestLists(
564569 return {
565570 viewers,
566571 providers : [ ...providers . values ( ) ] ,
567- entries : entries . toSorted ( ( left , right ) => right . updatedAt . localeCompare ( left . updatedAt ) ) ,
572+ entries : entries . toSorted ( comparePullRequestsByRecency ) ,
568573 errors,
569574 truncated,
570575 nextCursors,
@@ -660,7 +665,7 @@ export function rankPullRequestMatches<Entry extends PullRequestListEntry>(
660665 if ( query . trim ( ) . length === 0 ) return entries ;
661666 return entries . toSorted ( ( left , right ) => {
662667 const byScore = scorePullRequestMatch ( right , query ) - scorePullRequestMatch ( left , query ) ;
663- return byScore !== 0 ? byScore : right . updatedAt . localeCompare ( left . updatedAt ) ;
668+ return byScore !== 0 ? byScore : comparePullRequestsByRecency ( left , right ) ;
664669 } ) ;
665670}
666671
@@ -681,24 +686,29 @@ export function rankPullRequestsByMergeReadiness<Entry extends PullRequestListEn
681686 if ( byTier !== 0 ) return byTier ;
682687 const measured = Number ( hasMeasuredSize ( right ) ) - Number ( hasMeasuredSize ( left ) ) ;
683688 const sized = left . additions + left . deletions - ( right . additions + right . deletions ) ;
684- return measured || sized || right . updatedAt . localeCompare ( left . updatedAt ) ;
689+ return measured || sized || comparePullRequestsByRecency ( left , right ) ;
685690 } ) ;
686691}
687692
693+ export function comparePullRequestsByRecency (
694+ left : PullRequestListEntry ,
695+ right : PullRequestListEntry ,
696+ ) {
697+ const leftUpdated = toSortableTimestamp ( left . updatedAt ) ;
698+ const rightUpdated = toSortableTimestamp ( right . updatedAt ) ;
699+ const measured = Number ( leftUpdated === null ) - Number ( rightUpdated === null ) ;
700+ if ( measured !== 0 ) return measured ;
701+ if ( leftUpdated === null || rightUpdated === null ) return 0 ;
702+ return rightUpdated - leftUpdated ;
703+ }
704+
688705function rankByTierThenRecency < Entry extends PullRequestListEntry > (
689706 entries : ReadonlyArray < Entry > ,
690707 tier : ( entry : Entry ) => number ,
691708) : ReadonlyArray < Entry > {
692- const timestamp = ( entry : Entry ) => toSortableTimestamp ( entry . updatedAt ) ;
693709 return entries . toSorted ( ( left , right ) => {
694710 const byTier = tier ( left ) - tier ( right ) ;
695- if ( byTier !== 0 ) return byTier ;
696- const leftUpdated = timestamp ( left ) ;
697- const rightUpdated = timestamp ( right ) ;
698- const measured = Number ( leftUpdated === null ) - Number ( rightUpdated === null ) ;
699- if ( measured !== 0 ) return measured ;
700- if ( leftUpdated === null || rightUpdated === null ) return 0 ;
701- return rightUpdated - leftUpdated ;
711+ return byTier !== 0 ? byTier : comparePullRequestsByRecency ( left , right ) ;
702712 } ) ;
703713}
704714
0 commit comments