mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-19 19:20:49 +08:00
refactor(AuthFilesPage): optimize provider list generation using useMemo for better performance
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
@use '../../styles/variables' as *;
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
display: flex;
|
display: flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -143,7 +145,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sourceItem, .aliasItem {
|
.sourceItem,
|
||||||
|
.aliasItem {
|
||||||
cursor: grab;
|
cursor: grab;
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
@@ -175,8 +178,7 @@
|
|||||||
right: -3px;
|
right: -3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.aliasItem {
|
.aliasItem {}
|
||||||
}
|
|
||||||
|
|
||||||
.providerBadge {
|
.providerBadge {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
@@ -320,4 +322,4 @@
|
|||||||
&:hover {
|
&:hover {
|
||||||
background: var(--bg-error-light);
|
background: var(--bg-error-light);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,29 +249,31 @@ export function AuthFilesPage() {
|
|||||||
|
|
||||||
const disableControls = connectionStatus !== 'connected';
|
const disableControls = connectionStatus !== 'connected';
|
||||||
|
|
||||||
|
const providerList = useMemo(() => {
|
||||||
|
const providers = new Set<string>();
|
||||||
|
|
||||||
|
Object.keys(modelAlias).forEach((provider) => {
|
||||||
|
const key = provider.trim().toLowerCase();
|
||||||
|
if (key) providers.add(key);
|
||||||
|
});
|
||||||
|
|
||||||
|
files.forEach((file) => {
|
||||||
|
if (typeof file.type === 'string') {
|
||||||
|
const key = file.type.trim().toLowerCase();
|
||||||
|
if (key) providers.add(key);
|
||||||
|
}
|
||||||
|
if (typeof file.provider === 'string') {
|
||||||
|
const key = file.provider.trim().toLowerCase();
|
||||||
|
if (key) providers.add(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Array.from(providers);
|
||||||
|
}, [files, modelAlias]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
const loadAllModels = async () => {
|
const loadAllModels = async () => {
|
||||||
const providers = new Set<string>();
|
|
||||||
|
|
||||||
Object.keys(modelAlias).forEach((provider) => {
|
|
||||||
const key = provider.trim().toLowerCase();
|
|
||||||
if (key) providers.add(key);
|
|
||||||
});
|
|
||||||
|
|
||||||
files.forEach((file) => {
|
|
||||||
if (typeof file.type === 'string') {
|
|
||||||
const key = file.type.trim().toLowerCase();
|
|
||||||
if (key) providers.add(key);
|
|
||||||
}
|
|
||||||
if (typeof file.provider === 'string') {
|
|
||||||
const key = file.provider.trim().toLowerCase();
|
|
||||||
if (key) providers.add(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const providerList = Array.from(providers);
|
|
||||||
if (providerList.length === 0) {
|
if (providerList.length === 0) {
|
||||||
if (!cancelled) setAllProviderModels({});
|
if (!cancelled) setAllProviderModels({});
|
||||||
return;
|
return;
|
||||||
@@ -305,7 +307,7 @@ export function AuthFilesPage() {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [files, modelAlias]);
|
}, [providerList]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user