perf: compute check severity once per sort (#20342)

Co-authored-by: Orca Worker <orca-worker@localhost>
This commit is contained in:
OrcaWin
2026-09-12 18:12:00 -07:00
committed by GitHub
co-authored by Orca Worker
parent 230f834013
commit 3c7c846a1d
+5 -6
View File
@@ -25,12 +25,11 @@ export function getCheckSeverityRank(conclusion: string | null | undefined): num
export function sortChecksBySeverity<T extends Pick<PRCheckDetail, 'conclusion'>>(
checks: readonly T[]
): T[] {
if (checks.length < 2) {
return checks.slice()
}
return checks
.map((check, index) => ({ check, index }))
.sort(
(a, b) =>
getCheckSeverityRank(a.check.conclusion) - getCheckSeverityRank(b.check.conclusion) ||
a.index - b.index
)
.map((check, index) => ({ check, index, rank: getCheckSeverityRank(check.conclusion) }))
.sort((a, b) => a.rank - b.rank || a.index - b.index)
.map(({ check }) => check)
}