fix(optimizer): убрать лишние поиски и расчёты маршрутов

This commit is contained in:
Denozordec committed 2026-10-07 13:16:12 +07:00
1 parent 057f0d352a
commit 4fee9e371f
8 files changed
+164 -9

No files matched your search

+13 -3
View File
@@ -512,8 +512,17 @@ export function buildLiveOptimizerData(
}
}
const wanJhById = new Map<string, Map<string, WanJhLeg>>()
for (const leg of wanJhLegs) {
let byHost = wanJhById.get(leg.wanId)
if (!byHost) { byHost = new Map(); wanJhById.set(leg.wanId, byHost) }
// Keep the first match, as the former Array.find did.
if (!byHost.has(leg.jhId)) byHost.set(leg.jhId, leg)
}
const jhExMap = new Map<string, JhExLeg>()
for (const jh of jumpHosts) {
// Without a configured WAN, no full route can consume a JH→Exit leg.
for (const jh of home.wans.length ? jumpHosts : []) {
for (const ex of exitNodes) {
const jhRow = byId.get(jh.id)
const exRow = byId.get(ex.id)
@@ -544,10 +553,11 @@ export function buildLiveOptimizerData(
const fullRoutes: FullRoute[] = []
for (const wan of home.wans) {
for (const jh of jumpHosts) {
const hw = wanJhById.get(wan.id)?.get(jh.id)
if (!hw) continue
for (const ex of exitNodes) {
const hw = wanJhLegs.find((l) => l.wanId === wan.id && l.jhId === jh.id)
const je = jhExMap.get(`${jh.id}::${ex.id}`)
if (!hw || !je) continue
if (!je) continue
const totalPing = hw.pingMs + je.pingMs
const dl = Math.min(hw.dlMbps, je.dlMbps)
const ul = Math.min(hw.ulMbps, je.ulMbps)