mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 07:12:12 +03:00
fix: use .find() for lastUsed instead of filter+sort
The call-logs endpoint already returns entries sorted by timestamp DESC, so the first match for a given apiKeyName is guaranteed to be the most recent one. Replace O(K·M·log M) filter+sort with O(M) find.
This commit is contained in:
@@ -187,17 +187,11 @@ export default function ApiManagerPageClient() {
|
||||
(entry: any) => entry.apiKeyName === key.name
|
||||
);
|
||||
|
||||
// Find the most recent call-log for this key to determine lastUsed
|
||||
const keyLogs = (logs || []).filter(
|
||||
// The call-logs endpoint returns entries sorted by timestamp DESC,
|
||||
// so the first match is the most recent one.
|
||||
const lastUsed = (logs || []).find(
|
||||
(log: any) => log.apiKeyName === key.name
|
||||
);
|
||||
const lastUsed =
|
||||
keyLogs.length > 0
|
||||
? keyLogs.sort(
|
||||
(a: any, b: any) =>
|
||||
new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()
|
||||
)[0]?.timestamp
|
||||
: null;
|
||||
)?.timestamp || null;
|
||||
|
||||
stats[key.id] = {
|
||||
totalRequests: analyticsMatch?.requests ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user