chore: migrate store to redb
This commit is contained in:
1 parent
7f0286dc40
commit
9a8b6e52e9
12 files changed
+1954
-1365
No files matched your search
+8
-7
@@ -1,6 +1,6 @@
|
||||
use crate::models::*;
|
||||
use crate::store::{Store, read_json_file, write_json_atomic};
|
||||
use crate::search::MemoryIndex;
|
||||
use crate::store::{Store, read_json_file, write_json_atomic};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
@@ -100,12 +100,15 @@ impl MemoryState {
|
||||
let mut session_graph = self.session_graph.write().unwrap();
|
||||
update_fn(&mut session_graph);
|
||||
let wal_path = self.base_dir.join("wal.jsonl");
|
||||
if let Ok(payload) = serde_json::to_string(&*session_graph) {
|
||||
if let Ok(mut file) = std::fs::OpenOptions::new().create(true).append(true).open(&wal_path) {
|
||||
if let Ok(payload) = serde_json::to_string(&*session_graph)
|
||||
&& let Ok(mut file) = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(&wal_path)
|
||||
{
|
||||
use std::io::Write;
|
||||
let _ = writeln!(file, "{}", payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn apply_sync_write<F: FnOnce(&mut KnowledgeGraph)>(&self, update_fn: F) {
|
||||
let lock_path = self.base_dir.join("master.lock");
|
||||
@@ -142,7 +145,7 @@ impl MemoryState {
|
||||
pub fn rebuild_index(&self) {
|
||||
if let Ok(new_idx) = MemoryIndex::new() {
|
||||
let full = self.get_full_graph();
|
||||
for (_, e) in &full.entities {
|
||||
for e in full.entities.values() {
|
||||
let _ = new_idx.index_entity(e);
|
||||
}
|
||||
for t in self.tasks.read() {
|
||||
@@ -160,5 +163,3 @@ impl MemoryState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user