Perf: hoist hidden-usage-source logic out of Models component (#785)
This commit is contained in:
@@ -26,6 +26,14 @@ const WINDOWS_USAGE_FETCH_MAX_ATTEMPTS = 3;
|
|||||||
const USAGE_FETCH_RETRY_DELAY_MS = 1500;
|
const USAGE_FETCH_RETRY_DELAY_MS = 1500;
|
||||||
const USAGE_AUTO_REFRESH_INTERVAL_MS = 15_000;
|
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() {
|
export function Models() {
|
||||||
const { t } = useTranslation(['dashboard', 'settings']);
|
const { t } = useTranslation(['dashboard', 'settings']);
|
||||||
const gatewayStatus = useGatewayStore((state) => state.status);
|
const gatewayStatus = useGatewayStore((state) => state.status);
|
||||||
@@ -40,21 +48,6 @@ export function Models() {
|
|||||||
const [usagePage, setUsagePage] = useState(1);
|
const [usagePage, setUsagePage] = useState(1);
|
||||||
const [selectedUsageEntry, setSelectedUsageEntry] = useState<UsageHistoryEntry | null>(null);
|
const [selectedUsageEntry, setSelectedUsageEntry] = useState<UsageHistoryEntry | null>(null);
|
||||||
const [usageRefreshNonce, setUsageRefreshNonce] = useState(0);
|
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 {
|
function formatUsageSource(source?: string): string | undefined {
|
||||||
if (!source) return undefined;
|
if (!source) return undefined;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user