perf(server): fix broadcast loops, avoid locking db on index, eliminate O(N*M) search, and fix db loss

This commit is contained in:
Riz Ashraf committed 2026-09-22 06:33:32 +01:00
1 parent 1e39122e05
commit 27aba454e2
4 files changed
+69 -54

No files matched your search

+21 -15
View File
@@ -361,14 +361,28 @@ impl McpTool for OmniSearchHandler {
serde_json::to_value(&kg_entities).unwrap_or_default()
});
let mut matched_tasks = std::collections::HashSet::new();
let mut matched_snippets = std::collections::HashSet::new();
let mut matched_adrs = std::collections::HashSet::new();
for (id, typ, _, _, _) in &matches {
match typ.as_str() {
"task" => {
matched_tasks.insert(id.as_str());
}
"snippet" => {
matched_snippets.insert(id.as_str());
}
"adr" => {
matched_adrs.insert(id.as_str());
}
_ => {}
}
}
let tasks_json = state.tasks.read_with(|all_tasks| {
let filtered: Vec<_> = all_tasks
.iter()
.filter(|t| {
matches
.iter()
.any(|(id, typ, _, _, _)| id == &t.id && typ == "task")
})
.filter(|t| matched_tasks.contains(t.id.as_str()))
.collect();
serde_json::to_value(&filtered).unwrap_or_default()
});
@@ -376,11 +390,7 @@ impl McpTool for OmniSearchHandler {
let snippets_json = state.snippets.read_with(|all_snippets| {
let filtered: Vec<_> = all_snippets
.iter()
.filter(|s| {
matches
.iter()
.any(|(id, typ, _, _, _)| id == &s.name && typ == "snippet")
})
.filter(|s| matched_snippets.contains(s.name.as_str()))
.collect();
serde_json::to_value(&filtered).unwrap_or_default()
});
@@ -388,11 +398,7 @@ impl McpTool for OmniSearchHandler {
let adrs_json = state.adrs.read_with(|all_adrs| {
let filtered: Vec<_> = all_adrs
.iter()
.filter(|a| {
matches
.iter()
.any(|(id, typ, _, _, _)| id == &a.id && typ == "adr")
})
.filter(|a| matched_adrs.contains(a.id.as_str()))
.collect();
serde_json::to_value(&filtered).unwrap_or_default()
});