mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:50:43 +00:00
perf: avoid sort-for-single selection
This commit is contained in:
@@ -36,9 +36,14 @@ export function selectPendingApprovalRequest(params: {
|
||||
}
|
||||
|
||||
if (normalizeLowercaseStringOrEmpty(params.requested) === "latest") {
|
||||
return {
|
||||
pending: [...params.pending].toSorted((a, b) => (b.ts ?? 0) - (a.ts ?? 0))[0],
|
||||
};
|
||||
let latest = params.pending[0];
|
||||
for (let index = 1; index < params.pending.length; index += 1) {
|
||||
const pending = params.pending[index];
|
||||
if ((pending.ts ?? 0) > (latest.ts ?? 0)) {
|
||||
latest = pending;
|
||||
}
|
||||
}
|
||||
return { pending: latest };
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user