소스 검색

fix: provider proxy sort by delay

GyDi 2 년 전
부모
커밋
0bb1790206
3개의 변경된 파일15개의 추가작업 그리고 14개의 파일을 삭제
  1. 1 11
      src/components/proxy/proxy-item.tsx
  2. 3 3
      src/components/proxy/use-filter-sort.ts
  3. 11 0
      src/services/delay.ts

+ 1 - 11
src/components/proxy/proxy-item.tsx

@@ -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 () => {

+ 3 - 3
src/components/proxy/use-filter-sort.ts

@@ -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;

+ 11 - 0
src/services/delay.ts

@@ -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;