fix(proxy-resolver): 将 resolve_ops_proxy_config 改为异步调用避免阻塞事件循环

在 anyrouter/nekocode/sub2api/yescode 架构及 service.py 中,
将同步的 resolve_ops_proxy_config 替换为 resolve_ops_proxy_config_async,
通过 asyncio.to_thread 包装避免同步 DB 查询阻塞事件循环。
This commit is contained in:
fawney19
2026-03-17 18:06:15 +08:00
parent 8a21cb9a55
commit 460eb5434d
7 changed files with 35 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ from src.services.proxy_node.resolver import (
build_post_kwargs_async,
build_stream_kwargs,
build_stream_kwargs_async,
resolve_ops_proxy_config_async,
resolve_proxy_info_async,
)
@@ -97,3 +98,19 @@ class TestProxyResolverCompression:
"url": "socks5://proxy.example.com:1080",
"source": "provider",
}
@pytest.mark.asyncio
async def test_resolve_ops_proxy_config_async_preserves_legacy_proxy(
self,
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(
"src.services.proxy_node.resolver.get_system_proxy_config",
lambda: None,
)
proxy, tunnel_node_id = await resolve_ops_proxy_config_async(
{"proxy": "http://proxy.example.com:8080"}
)
assert proxy == "http://proxy.example.com:8080"
assert tunnel_node_id is None