Perf: hoist hidden-usage-source logic out of Models component (#785)

This commit is contained in:
phpoh
2026-04-08 15:13:09 +08:00
committed by GitHub
Unverified
parent 25b13ab912
commit 0b3152f7f2

View File

@@ -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<UsageHistoryEntry | null>(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;