fix: provider proxy sort by delay

This commit is contained in:
GyDi 2022-11-11 01:21:23 +08:00
parent 45fc84d8be
commit 0bb1790206
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A
3 changed files with 15 additions and 14 deletions

View File

@ -59,17 +59,7 @@ const ProxyItem = (props: Props) => {
useEffect(() => {
if (!proxy) return;
if (!proxy.provider) {
setDelay(delayManager.getDelay(proxy.name, groupName));
return;
}
const { history = [] } = proxy;
if (history.length > 0) {
// 0ms以error显示
setDelay(history[history.length - 1].delay || 1e6);
}
setDelay(delayManager.getDelayFix(proxy, groupName));
}, [proxy]);
const onDelay = useLockFn(async () => {

View File

@ -61,7 +61,7 @@ function filterProxies(
symbol2 === "error" ? 1e5 : symbol2 === "timeout" ? 3000 : +symbol2;
return proxies.filter((p) => {
const delay = delayManager.getDelay(p.name, groupName);
const delay = delayManager.getDelayFix(p, groupName);
if (delay < 0) return false;
if (symbol === "=" && symbol2 === "error") return delay >= 1e5;
@ -98,8 +98,8 @@ function sortProxies(
if (sortType === 1) {
list.sort((a, b) => {
const ad = delayManager.getDelay(a.name, groupName);
const bd = delayManager.getDelay(b.name, groupName);
const ad = delayManager.getDelayFix(a, groupName);
const bd = delayManager.getDelayFix(b, groupName);
if (ad === -1 || ad === -2) return 1;
if (bd === -1 || bd === -2) return -1;

View File

@ -55,6 +55,17 @@ class DelayManager {
return -1;
}
/// 暂时修复provider的节点延迟排序的问题
getDelayFix(proxy: ApiType.ProxyItem, group: string) {
if (!proxy.provider) return this.getDelay(proxy.name, group);
if (proxy.history.length > 0) {
// 0ms以error显示
return proxy.history[proxy.history.length - 1].delay || 1e6;
}
return -1;
}
async checkDelay(name: string, group: string) {
let delay = -1;