fix: update logging types and clean up ProxyRequestCache usage

This commit is contained in:
Tunglies
2025-09-02 22:19:22 +08:00
parent 926c095409
commit b51797e238
5 changed files with 42 additions and 22 deletions

View File

@@ -6,7 +6,7 @@
### 🚀 性能优化 ### 🚀 性能优化
- 优化节点信息缓存占用 - 优化存占用
### 🐞 修复问题 ### 🐞 修复问题
@@ -15,7 +15,7 @@
- 修复2.4.1引入的订阅地址重定向报错问题 - 修复2.4.1引入的订阅地址重定向报错问题
- 修复 rpm/deb 包名称问题 - 修复 rpm/deb 包名称问题
- 修复托盘轻量模式状态检测异常 - 修复托盘轻量模式状态检测异常
- 修复通过 scheme 导入订阅 - 修复通过 scheme 导入订阅
- 修复单例检测实效 - 修复单例检测实效
### 👙 界面样式 ### 👙 界面样式

View File

@@ -24,8 +24,7 @@ fn create_error(msg: impl Into<String>) -> AnyError {
} }
pub struct IpcManager { pub struct IpcManager {
ipc_path: String, client: IpcHttpClient,
config: ClientConfig,
} }
impl IpcManager { impl IpcManager {
@@ -41,25 +40,25 @@ impl IpcManager {
std::path::PathBuf::from("/tmp/clash-verge-ipc") // fallback path std::path::PathBuf::from("/tmp/clash-verge-ipc") // fallback path
}); });
let ipc_path = ipc_path_buf.to_str().unwrap_or_default(); let ipc_path = ipc_path_buf.to_str().unwrap_or_default();
Self { let config = ClientConfig {
ipc_path: ipc_path.to_string(), default_timeout: Duration::from_secs(5),
config: ClientConfig { enable_pooling: true,
default_timeout: Duration::from_secs(5), max_retries: 3,
enable_pooling: true, max_concurrent_requests: 64,
max_requests_per_second: Some(10.0),
pool_config: PoolConfig {
max_size: 64,
min_idle: 8,
max_idle_time_ms: 60_000,
max_retries: 3, max_retries: 3,
max_concurrent_requests: 32, max_concurrent_requests: 64,
max_requests_per_second: Some(5.0), max_requests_per_second: Some(10.0),
pool_config: PoolConfig {
max_size: 32,
min_idle: 2,
max_idle_time_ms: 10_000,
max_retries: 3,
max_concurrent_requests: 32,
max_requests_per_second: Some(5.0),
..Default::default()
},
..Default::default() ..Default::default()
}, },
..Default::default()
};
Self {
client: IpcHttpClient::with_config(ipc_path, config).unwrap(),
} }
} }
} }
@@ -74,8 +73,7 @@ impl IpcManager {
path: &str, path: &str,
body: Option<&serde_json::Value>, body: Option<&serde_json::Value>,
) -> AnyResult<LegacyResponse> { ) -> AnyResult<LegacyResponse> {
let client = IpcHttpClient::with_config(&self.ipc_path, self.config.clone())?; self.client.request(method, path, body).await
client.request(method, path, body).await
} }
} }

View File

@@ -3,6 +3,7 @@ use crate::{
core::{handle, timer::Timer, tray::Tray}, core::{handle, timer::Timer, tray::Tray},
log_err, logging, log_err, logging,
process::AsyncHandler, process::AsyncHandler,
state::proxy::ProxyRequestCache,
utils::{logging::Type, window_manager::WindowManager}, utils::{logging::Type, window_manager::WindowManager},
}; };
@@ -153,6 +154,7 @@ pub async fn entry_lightweight_mode() {
} }
set_lightweight_mode(true).await; set_lightweight_mode(true).await;
let _ = cancel_light_weight_timer(); let _ = cancel_light_weight_timer();
ProxyRequestCache::global().clean_default_keys();
// 更新托盘显示 // 更新托盘显示
logging_error!(Type::Lightweight, true, Tray::global().update_part().await); logging_error!(Type::Lightweight, true, Tray::global().update_part().await);

View File

@@ -1,3 +1,5 @@
// use crate::utils::logging::Type;
// use crate::{logging, singleton};
use crate::singleton; use crate::singleton;
use dashmap::DashMap; use dashmap::DashMap;
use serde_json::Value; use serde_json::Value;
@@ -78,6 +80,22 @@ impl ProxyRequestCache {
} }
} }
} }
// TODO
pub fn clean_default_keys(&self) {
// logging!(info, Type::Cache, "Cleaning proxies keys");
// let proxies_key = Self::make_key("proxies", "default");
// self.map.remove(&proxies_key);
// logging!(info, Type::Cache, "Cleaning providers keys");
// let providers_key = Self::make_key("providers", "default");
// self.map.remove(&providers_key);
// !The frontend goes crash if we clean the clash_config cache
// logging!(info, Type::Cache, "Cleaning clash config keys");
// let clash_config_key = Self::make_key("clash_config", "default");
// self.map.remove(&clash_config_key);
}
} }
// Use singleton macro // Use singleton macro

View File

@@ -18,6 +18,7 @@ pub enum Type {
Network, Network,
ProxyMode, ProxyMode,
Ipc, Ipc,
// Cache,
} }
impl fmt::Display for Type { impl fmt::Display for Type {
@@ -39,6 +40,7 @@ impl fmt::Display for Type {
Type::Network => write!(f, "[Network]"), Type::Network => write!(f, "[Network]"),
Type::ProxyMode => write!(f, "[ProxMode]"), Type::ProxyMode => write!(f, "[ProxMode]"),
Type::Ipc => write!(f, "[IPC]"), Type::Ipc => write!(f, "[IPC]"),
// Type::Cache => write!(f, "[Cache]"),
} }
} }
} }