forked from kent/consciousness
store: index ops take WriteTransaction, mutations batch properly
Index functions now take &WriteTransaction instead of &Database, allowing callers to batch multiple index operations in a single transaction. Store mutations (upsert, delete, rename, etc.) now begin_write/commit their own transactions, ensuring atomicity. - replay_relations uses single txn for all relation indexing - Store::db() exposes Database for callers needing txn control - Convenience wrappers open their own txn for simple cases Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
2548ca059d
commit
4696bb8b7d
5 changed files with 151 additions and 144 deletions
|
|
@ -354,12 +354,14 @@ impl Store {
|
|||
}
|
||||
}
|
||||
|
||||
// Index relations directly (no Vec intermediate)
|
||||
// Index relations directly (single transaction)
|
||||
if let Some(db) = &self.db {
|
||||
let txn = db.begin_write()?;
|
||||
for rel in by_uuid.into_values() {
|
||||
if rel.deleted { continue; }
|
||||
index::index_relation(db, &rel.source, &rel.target, rel.strength, rel.rel_type as u8)?;
|
||||
index::index_relation(&txn, &rel.source, &rel.target, rel.strength, rel.rel_type as u8)?;
|
||||
}
|
||||
txn.commit()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue