refactor: apply rust best practices and fix memory optimizations
- Optimized memory allocation in router.rs by offloading JSON serialization to spawn_blocking and using references. - Prevented full graph duplication on startup in state.rs index rebuild. - Eliminated massive String allocations in QueryGraphPathHandler BFS loops. - Avoided temporary Strings in VisualizeGraphHandler via inline writing. - Fixed O(N) full-graph deduplication in MergeEntitiesHandler to scale efficiently.
This commit is contained in:
1 parent
251757f8fc
commit
37003be620
17 files changed
+399
-198
No files matched your search
+11
-4
@@ -113,8 +113,8 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::router::MemoryHandler;
|
||||
use crate::state::MemoryState;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[tokio::test]
|
||||
@@ -137,7 +137,9 @@ mod tests {
|
||||
block: None,
|
||||
reason: None,
|
||||
};
|
||||
let res_set = gate_set_handler(State(app_state.clone()), Json(set_req)).await.unwrap();
|
||||
let res_set = gate_set_handler(State(app_state.clone()), Json(set_req))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(res_set.into_response().status(), axum::http::StatusCode::OK);
|
||||
|
||||
// Verify the gate (and consume it)
|
||||
@@ -148,8 +150,13 @@ mod tests {
|
||||
params: HashMap::new(),
|
||||
consume: true,
|
||||
};
|
||||
let res_verify = gate_verify_handler(State(app_state.clone()), Query(verify_req)).await.unwrap();
|
||||
assert_eq!(res_verify.into_response().status(), axum::http::StatusCode::OK);
|
||||
let res_verify = gate_verify_handler(State(app_state.clone()), Query(verify_req))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
res_verify.into_response().status(),
|
||||
axum::http::StatusCode::OK
|
||||
);
|
||||
|
||||
// Verify again should fail since it was consumed
|
||||
let verify_req2 = GateVerifyReq {
|
||||
|
||||
Reference in new issue
Block a user