mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 21:10:43 +00:00
perf: avoid sort-for-single selection
This commit is contained in:
@@ -199,10 +199,15 @@ function resolveDreamingNextCycle(
|
||||
if (!status?.phases) {
|
||||
return null;
|
||||
}
|
||||
const nextRunAtMs = Object.values(status.phases)
|
||||
.filter((phase) => phase.enabled && typeof phase.nextRunAtMs === "number")
|
||||
.map((phase) => phase.nextRunAtMs as number)
|
||||
.toSorted((a, b) => a - b)[0];
|
||||
let nextRunAtMs: number | undefined;
|
||||
for (const phase of Object.values(status.phases)) {
|
||||
if (!phase.enabled || typeof phase.nextRunAtMs !== "number") {
|
||||
continue;
|
||||
}
|
||||
if (nextRunAtMs === undefined || phase.nextRunAtMs < nextRunAtMs) {
|
||||
nextRunAtMs = phase.nextRunAtMs;
|
||||
}
|
||||
}
|
||||
return formatDreamNextCycle(nextRunAtMs);
|
||||
}
|
||||
|
||||
|
||||
@@ -579,15 +579,25 @@ const buildUsageInsightStats = (
|
||||
const errorRate = aggregates.messages.total
|
||||
? aggregates.messages.errors / aggregates.messages.total
|
||||
: 0;
|
||||
const peakErrorDay = aggregates.daily
|
||||
.filter((day) => day.messages > 0 && day.errors > 0)
|
||||
.map((day) => ({
|
||||
let peakErrorDay: UsageInsightStats["peakErrorDay"];
|
||||
for (const day of aggregates.daily) {
|
||||
if (day.messages <= 0 || day.errors <= 0) {
|
||||
continue;
|
||||
}
|
||||
const candidate = {
|
||||
date: day.date,
|
||||
errors: day.errors,
|
||||
messages: day.messages,
|
||||
rate: day.errors / day.messages,
|
||||
}))
|
||||
.toSorted((a, b) => b.rate - a.rate || b.errors - a.errors)[0];
|
||||
};
|
||||
if (
|
||||
!peakErrorDay ||
|
||||
candidate.rate > peakErrorDay.rate ||
|
||||
(candidate.rate === peakErrorDay.rate && candidate.errors > peakErrorDay.errors)
|
||||
) {
|
||||
peakErrorDay = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
durationSumMs,
|
||||
|
||||
Reference in New Issue
Block a user