Optimize graph relation filtering and fix concurrent connection storms
This commit is contained in:
1 parent
cbd3d5801c
commit
ed42f738f1
2 files changed
+6
-21
No files matched your search
@@ -126,12 +126,10 @@ pub struct NvimRequest {
|
||||
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> {
|
||||
{
|
||||
let conn_lock = NVIM_CONN.lock().await;
|
||||
if let Some(sender) = conn_lock.as_ref() {
|
||||
if !sender.is_closed() {
|
||||
return Ok(sender.clone());
|
||||
}
|
||||
let mut conn_lock = NVIM_CONN.lock().await;
|
||||
if let Some(sender) = conn_lock.as_ref() {
|
||||
if !sender.is_closed() {
|
||||
return Ok(sender.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
Ok(tx)
|
||||
}
|
||||
@@ -1004,7 +1001,6 @@ fn init_logging(app_name: &str) -> tracing_appender::non_blocking::WorkerGuard {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tokio::io::BufReader;
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
#[test]
|
||||
fn test_rmpv_to_json_primitives() {
|
||||
|
||||
+2
-13
@@ -511,19 +511,8 @@ impl MemoryHandler {
|
||||
"delete_relations" => {
|
||||
let req = parse_tool!(args.clone(), id, DeleteRelationsTool);
|
||||
self.state.modify_graph(|master| {
|
||||
let mut to_rem = HashSet::new();
|
||||
for r in req.relations {
|
||||
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
|
||||
))
|
||||
});
|
||||
let to_rem: HashSet<_> = req.relations.into_iter().collect();
|
||||
master.relations.retain(|r| !to_rem.contains(r));
|
||||
});
|
||||
Ok("Relations deleted".to_string())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user