feat: share httpx client + cache ProxyDecider across modules#4
Closed
power721 wants to merge 1 commit into
Closed
Conversation
Introduce NetworkClient that maintains a small pool of long-lived httpx.Client instances keyed by ProxyDecision (direct/system/manual:<url>) plus a shared requests.Session, eliminating per-request TCP+TLS handshakes across proxy server, plugin spider compat layer, poster loader, main window hot-search loaders, player window subtitle fetch, and danmaku/metadata service factories. AdvancedSettingsDialog saves now compare the proxy signature and invalidate only the system/manual clients on change while keeping the direct client warm. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NetworkClient:按ProxyDecision.kind维护 ≤3 个长存httpx.Client(direct / system / manual:)+ 1 个长存requests.Session,池上限 10,线程安全AppCoordinator集中持有 NetworkClient,并为 5 个调用点(plugin spider session、poster_loader、main_window get+post、player_window get)注册 loader,全部走共享客户端AdvancedSettingsDialog经包装的save_config仅在 proxy 三字段变化时调用invalidate_proxy();direct 客户端不受影响保留 keep-aliveload_config()调用主要文件改动
src/atv_player/network_client.py_default_client_factory/_default_session_factorysrc/atv_player/app.py_proxy_http_*简化;5 个 loader 注册;close()关闭网络层src/atv_player/plugins/compat/base/spider.pyset_session_loader+fetch/post走 Sessionsrc/atv_player/ui/poster_loader.pyset_http_get_loader,默认get=None时走 loadersrc/atv_player/ui/main_window.pyhttpx.get/post改为_resolve_http_get/_resolve_http_postsrc/atv_player/ui/player_window.pyhttpx.get(外挂字幕)改用 loader;移除冗余get=httpx.getTest plan
ruff check在 6 个改动文件中全绿test_browse_page_ui / test_build / test_mpv_widget:失败集完全一致(15 条),零新增回归已知 pre-existing 测试问题(与本 PR 无关)
test_app.py、test_main_window_ui.py、test_player_window_ui.py中部分测试在 origin/master 上即已 hang/fail(mock 漏get参数、plugin 启动加载相关),跳过比对而非引入。🤖 Generated with Claude Code