Optimize handlers to avoid deep clones of KnowledgeGraph, and fix database write concurrency issues

This commit is contained in:
Riz Ashraf committed 2026-09-21 06:53:32 +01:00
1 parent 7a48fa5d34
commit 9b349e6459
4 files changed
+197 -170

No files matched your search

+8 -8
View File
@@ -214,12 +214,10 @@ async fn gate_set_handler(
(axum::http::StatusCode::OK, "Gate state updated.").into_response()
}
fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
state.rebuild_index().await;
tokio::spawn(index_committer_worker(Arc::clone(&state)));
let app_state = Arc::new(AppState {
async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::Error>> {
state.rebuild_index().await;
tokio::spawn(index_committer_worker(Arc::clone(&state)));
let app_state = Arc::new(AppState {
handler: Arc::new(MemoryHandler {
state: Arc::clone(&state),
}),
@@ -427,7 +425,6 @@ fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::error::Error>>
let _ = tokio::fs::write(&log_path, format!("Server crashed: {}\n", e)).await;
}
Ok(())
})
}
async fn ws_handler(
@@ -796,6 +793,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
write_txn.commit().unwrap();
}
let rt = tokio::runtime::Runtime::new().unwrap();
let _guard = rt.enter();
let state = Arc::new(MemoryState {
graph: Store::new("knowledge_graph_master", db.clone()),
base_dir: base.clone(),
@@ -830,5 +830,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
activity_tx: tokio::sync::broadcast::channel(100).0,
});
run_server(state)
rt.block_on(run_server(state))
}