Optimize graph relation filtering and fix concurrent connection storms
This commit is contained in:
1 parent
cbd3d5801c
commit
ed42f738f1
2 files changed
+3
-18
No files matched your search
@@ -126,14 +126,12 @@ pub struct NvimRequest {
|
|||||||
static NVIM_CONN: LazyLock<Arc<Mutex<Option<mpsc::Sender<NvimRequest>>>>> = LazyLock::new(|| Arc::new(Mutex::new(None)));
|
static NVIM_CONN: LazyLock<Arc<Mutex<Option<mpsc::Sender<NvimRequest>>>>> = LazyLock::new(|| Arc::new(Mutex::new(None)));
|
||||||
|
|
||||||
async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
||||||
{
|
let mut conn_lock = NVIM_CONN.lock().await;
|
||||||
let conn_lock = NVIM_CONN.lock().await;
|
|
||||||
if let Some(sender) = conn_lock.as_ref() {
|
if let Some(sender) = conn_lock.as_ref() {
|
||||||
if !sender.is_closed() {
|
if !sender.is_closed() {
|
||||||
return Ok(sender.clone());
|
return Ok(sender.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tracing::info!("Establishing new persistent connection to Neovim");
|
tracing::info!("Establishing new persistent connection to Neovim");
|
||||||
let socket_path = get_socket_path().await?;
|
let socket_path = get_socket_path().await?;
|
||||||
@@ -243,7 +241,6 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut conn_lock = NVIM_CONN.lock().await;
|
|
||||||
*conn_lock = Some(tx.clone());
|
*conn_lock = Some(tx.clone());
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
@@ -1004,7 +1001,6 @@ fn init_logging(app_name: &str) -> tracing_appender::non_blocking::WorkerGuard {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use tokio::io::BufReader;
|
use tokio::io::BufReader;
|
||||||
use tokio::io::AsyncReadExt;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rmpv_to_json_primitives() {
|
fn test_rmpv_to_json_primitives() {
|
||||||
|
|||||||
+2
-13
@@ -511,19 +511,8 @@ impl MemoryHandler {
|
|||||||
"delete_relations" => {
|
"delete_relations" => {
|
||||||
let req = parse_tool!(args.clone(), id, DeleteRelationsTool);
|
let req = parse_tool!(args.clone(), id, DeleteRelationsTool);
|
||||||
self.state.modify_graph(|master| {
|
self.state.modify_graph(|master| {
|
||||||
let mut to_rem = HashSet::new();
|
let to_rem: HashSet<_> = req.relations.into_iter().collect();
|
||||||
for r in req.relations {
|
master.relations.retain(|r| !to_rem.contains(r));
|
||||||
to_rem.insert(format!(
|
|
||||||
"{}|{}|{}|{}",
|
|
||||||
r.from, r.to, r.relation_type, r.namespace
|
|
||||||
));
|
|
||||||
}
|
|
||||||
master.relations.retain(|r| {
|
|
||||||
!to_rem.contains(&format!(
|
|
||||||
"{}|{}|{}|{}",
|
|
||||||
r.from, r.to, r.relation_type, r.namespace
|
|
||||||
))
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
Ok("Relations deleted".to_string())
|
Ok("Relations deleted".to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user