Optimize full graph rebuilds with batch indexing to prevent thread exhaustion, and fix adr/snippet search availability before restart
This commit is contained in:
1 parent
84672a00b9
commit
a9885a65d7
3 files changed
+102
-47
No files matched your search
+35
-16
@@ -978,19 +978,27 @@ impl MemoryHandler {
|
||||
}
|
||||
"store_snippet" => {
|
||||
let req = parse_tool!(args.clone(), id, StoreSnippetTool);
|
||||
let snippet = Snippet {
|
||||
name: req.name.clone(),
|
||||
language: req.language,
|
||||
code: req.code,
|
||||
description: req.description,
|
||||
updated_at: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs(),
|
||||
};
|
||||
|
||||
let s_clone = snippet.clone();
|
||||
self.state.snippets.modify(|snippets| {
|
||||
snippets.retain(|s| s.name != req.name);
|
||||
snippets.push(Snippet {
|
||||
name: req.name.clone(),
|
||||
language: req.language,
|
||||
code: req.code,
|
||||
description: req.description,
|
||||
updated_at: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs(),
|
||||
});
|
||||
snippets.push(s_clone);
|
||||
});
|
||||
|
||||
if let Ok(idx) = self.state.search_index.read() {
|
||||
drop(idx.index_snippet(&snippet));
|
||||
}
|
||||
|
||||
Ok(format!("Snippet '{}' stored.", req.name).to_string())
|
||||
}
|
||||
"search_snippets" => {
|
||||
@@ -1025,11 +1033,13 @@ impl MemoryHandler {
|
||||
}
|
||||
"log_decision" => {
|
||||
let req = parse_tool!(args.clone(), id, LogDecisionTool);
|
||||
let mut id = String::new();
|
||||
let mut adr_id = String::new();
|
||||
let mut new_adr = None;
|
||||
|
||||
self.state.adrs.modify(|adrs| {
|
||||
id = format!("ADR-{:04}", adrs.len() + 1);
|
||||
adrs.push(Adr {
|
||||
id: id.clone(),
|
||||
adr_id = format!("ADR-{:04}", adrs.len() + 1);
|
||||
let a = Adr {
|
||||
id: adr_id.clone(),
|
||||
title: req.title,
|
||||
context: req.context,
|
||||
decision: req.decision,
|
||||
@@ -1038,9 +1048,18 @@ impl MemoryHandler {
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs(),
|
||||
});
|
||||
};
|
||||
new_adr = Some(a.clone());
|
||||
adrs.push(a);
|
||||
});
|
||||
Ok(format!("Decision logged as {}", id).to_string())
|
||||
|
||||
if let Some(adr) = new_adr {
|
||||
if let Ok(idx) = self.state.search_index.read() {
|
||||
drop(idx.index_adr(&adr));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(format!("Decision logged as {}", adr_id).to_string())
|
||||
}
|
||||
"query_decisions" => {
|
||||
let req = parse_tool!(args.clone(), id, QueryDecisionsTool);
|
||||
|
||||
Reference in new issue
Block a user