store: add reindex_relations for after Vec mutations

- Add index::clear_relations() to drop and recreate RELS table
- Add Store::reindex_relations() to rebuild index from Vec
- Call reindex_relations() at end of dedup command

This ensures index stays in sync with Vec after complex mutations
like UUID redirection in dedup. Vec mutations remain for now but
index is correctly updated afterward.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-13 21:24:49 -04:00
commit c2de14dcab
3 changed files with 27 additions and 2 deletions

View file

@ -209,6 +209,18 @@ pub fn remove_relation(
Ok(())
}
/// Clear all relations from the index.
pub fn clear_relations(db: &Database) -> Result<()> {
let txn = db.begin_write()?;
{
// Drop and recreate the table
txn.delete_multimap_table(RELS)?;
let _ = txn.open_multimap_table(RELS)?;
}
txn.commit()?;
Ok(())
}
/// Get all edges for a node. Returns (other_uuid, strength, rel_type, is_outgoing).
pub fn edges_for_node(db: &Database, node_uuid: &[u8; 16]) -> Result<Vec<([u8; 16], f32, u8, bool)>> {
let txn = db.begin_read()?;