From 0b3152f7f2a00d98f423cd46caf1ce4f77bfc3c8 Mon Sep 17 00:00:00 2001 From: phpoh <64546661+phpoh@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:13:09 +0800 Subject: [PATCH] Perf: hoist hidden-usage-source logic out of Models component (#785) --- src/pages/Models/index.tsx | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/pages/Models/index.tsx b/src/pages/Models/index.tsx index 5a6bf346d..c17170294 100644 --- a/src/pages/Models/index.tsx +++ b/src/pages/Models/index.tsx @@ -26,6 +26,14 @@ const WINDOWS_USAGE_FETCH_MAX_ATTEMPTS = 3; const USAGE_FETCH_RETRY_DELAY_MS = 1500; const USAGE_AUTO_REFRESH_INTERVAL_MS = 15_000; +const HIDDEN_USAGE_MARKERS = ['gateway-injected', 'delivery-mirror']; + +function isHiddenUsageSource(source?: string): boolean { + if (!source) return false; + const normalizedSource = source.trim().toLowerCase(); + return HIDDEN_USAGE_MARKERS.some((marker) => normalizedSource.includes(marker)); +} + export function Models() { const { t } = useTranslation(['dashboard', 'settings']); const gatewayStatus = useGatewayStore((state) => state.status); @@ -40,21 +48,6 @@ export function Models() { const [usagePage, setUsagePage] = useState(1); const [selectedUsageEntry, setSelectedUsageEntry] = useState(null); const [usageRefreshNonce, setUsageRefreshNonce] = useState(0); - const HIDDEN_USAGE_SOURCES = new Set([ - 'gateway-injected', - 'delivery-mirror', - ]); - - function isHiddenUsageSource(source?: string): boolean { - if (!source) return false; - const normalizedSource = source.trim().toLowerCase(); - return ( - HIDDEN_USAGE_SOURCES.has(normalizedSource) - || normalizedSource.includes('gateway-injected') - || normalizedSource.includes('delivery-mirror') - ); - } - function formatUsageSource(source?: string): string | undefined { if (!source) return undefined;