mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 05:15:35 +08:00
refactor(proxies): use connection msg instead of active connections for better performance
This commit is contained in:
parent
a8cb75f29d
commit
a7213df135
@ -69,7 +69,7 @@ export const useConnections = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function restructRawMsgToConnection(
|
export function restructRawMsgToConnection(
|
||||||
connections: ConnectionRawMessage[],
|
connections: ConnectionRawMessage[],
|
||||||
prevActiveConnections: Connection[],
|
prevActiveConnections: Connection[],
|
||||||
): Connection[] {
|
): Connection[] {
|
||||||
@ -95,7 +95,7 @@ function restructRawMsgToConnection(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeAllConnections(activeConns: Connection[]) {
|
export function mergeAllConnections(activeConns: Connection[]) {
|
||||||
return unionWith(allConnections(), activeConns, (a, b) => a.id === b.id)
|
return unionWith(allConnections(), activeConns, (a, b) => a.id === b.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,11 @@ import {
|
|||||||
useRequest,
|
useRequest,
|
||||||
} from '~/signals'
|
} from '~/signals'
|
||||||
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
|
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
|
||||||
import { useConnections } from './connections'
|
import {
|
||||||
|
latestConnectionMsg,
|
||||||
|
mergeAllConnections,
|
||||||
|
restructRawMsgToConnection,
|
||||||
|
} from './connections'
|
||||||
|
|
||||||
type ProxyInfo = {
|
type ProxyInfo = {
|
||||||
name: string
|
name: string
|
||||||
@ -47,7 +51,6 @@ const setProxiesInfo = (proxies: (Proxy | ProxyNode)[]) => {
|
|||||||
|
|
||||||
export const useProxies = () => {
|
export const useProxies = () => {
|
||||||
const request = useRequest()
|
const request = useRequest()
|
||||||
const { activeConnections } = useConnections()
|
|
||||||
|
|
||||||
const updateProxies = async () => {
|
const updateProxies = async () => {
|
||||||
const [{ providers }, { proxies }] = await Promise.all([
|
const [{ providers }, { proxies }] = await Promise.all([
|
||||||
@ -89,11 +92,22 @@ export const useProxies = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (autoCloseConns()) {
|
if (autoCloseConns()) {
|
||||||
activeConnections().forEach(({ id, chains }) => {
|
// we dont use activeConns from useConnection here for better performance
|
||||||
if (chains.includes(proxy.name)) {
|
// and we use empty array to restruct msg because they are closed and they won't have speed anyway
|
||||||
request.delete(`connections/${id}`)
|
|
||||||
}
|
const activeConns = restructRawMsgToConnection(
|
||||||
})
|
latestConnectionMsg()?.connections ?? [],
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
|
if (activeConns.length > 0) {
|
||||||
|
activeConns.forEach(({ id, chains }) => {
|
||||||
|
if (chains.includes(proxy.name)) {
|
||||||
|
request.delete(`connections/${id}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
mergeAllConnections(activeConns)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyGroup.now = proxyName
|
proxyGroup.now = proxyName
|
||||||
|
Loading…
Reference in New Issue
Block a user