Skip to content

Commit 6482a08

Browse files
committed
perf(api): 缓存 busybox 路径,避免每次请求重复探测
api_request 原每次调用 fork $(detect_busybox);改为 source 时 探测一次缓存到 API_BUSYBOX,并优先复用调用方已有的 BUSYBOX。 cli node delay all 等循环调用控制接口的场景不再按节点数重复探测。
1 parent 69a9d22 commit 6482a08

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • src/module/scripts/utils

src/module/scripts/utils/api.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
# CLASH_API / CLASH_SECRET / SELECTOR_GROUP / DELAY_URL 常量。
99
#######################################
1010

11+
# busybox 路径:引入时探测一次并缓存 (沿用调用方已有的 BUSYBOX),
12+
# 供 api_request 反复调用 nc 时复用,避免每次请求重复探测
13+
API_BUSYBOX="${BUSYBOX:-$(detect_busybox)}"
14+
1115
#######################################
1216
# 读取控制器地址 (host:port)
1317
# 参数: 无
@@ -103,7 +107,7 @@ api_request() {
103107
printf "Connection: close\r\n"
104108
printf "\r\n"
105109
[ -n "$data" ] && printf "%s" "$data"
106-
} | "$(detect_busybox)" nc "$host" "$port" 2>/dev/null )
110+
} | "$API_BUSYBOX" nc "$host" "$port" 2>/dev/null )
107111
status=$?
108112

109113
# 取首行状态行用于判断结果

0 commit comments

Comments
 (0)