mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
perf: compute check severity once per sort (#20342)
Co-authored-by: Orca Worker <orca-worker@localhost>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user