Refactor: Cache Proxy HTTP Clients with Reset on Channel Updates - #1894
Conversation
WalkthroughAdds a mutex-guarded cache of proxy Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Controller
participant Service as Service (HTTP Client Cache)
note over Service: Map[proxyURL]*http.Client + Mutex
Caller->>Controller: AddChannel/UpdateChannel(...)
Controller->>Controller: Persist changes and refresh channel cache
Controller->>Service: ResetProxyClientCache()
activate Service
Service->>Service: For each cached client: CloseIdleConnections()
Service->>Service: Clear and reinit cache map
deactivate Service
Controller-->>Caller: Success
sequenceDiagram
autonumber
participant Code as Caller
participant Service as Service (HTTP Client Cache)
Code->>Service: GetHTTPClient(proxyURL)
alt proxyURL == ""
Service-->>Code: http.DefaultClient
else proxyURL in cache
Service-->>Code: Cached *http.Client
else (cache miss)
Service->>Service: Create *http.Client (http/https or socks5 transport + Timeout)
Service->>Service: Store in cache
Service-->>Code: New *http.Client
end
rect rgba(235,248,255,0.6)
note right of Service: On channel add/update -> ResetProxyClientCache() closes idle conns and clears cache
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
controller/channel.go(3 hunks)service/http_client.go(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
controller/channel.go (1)
service/http_client.go (1)
ResetProxyClientCache(37-46)
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
service/http_client.go(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
service/http_client.go (1)
common/constants.go (1)
RelayTimeout(121-121)
…annel-proxy Refactor: Cache Proxy HTTP Clients with Reset on Channel Updates
PR 类型
PR 是否包含破坏性更新?
PR 描述
close #1863
动机
涉及改动
ResetProxyClientCache 用于清理缓存和关闭空闲连接。
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Chores