move all inserts into a single transaction

feat/vaults
Tomáš Mládek 2021-12-04 18:49:11 +01:00
parent dd765ee94b
commit bc97b8bc8f
1 changed files with 6 additions and 5 deletions

View File

@ -274,29 +274,24 @@ fn _process_directory_entry<P: AsRef<Path>>(
mtime,
};
insert_file(connection, new_file)?;
// Insert metadata
let type_entry = Entry {
entity: Address::Hash(file_hash.clone()),
attribute: String::from(IS_OF_TYPE_ATTR),
value: EntryValue::Address(BLOB_TYPE_ADDR.clone()),
};
insert_entry(connection, type_entry)?;
let size_entry = Entry {
entity: Address::Hash(file_hash.clone()),
attribute: FILE_SIZE_KEY.to_string(),
value: EntryValue::Value(Value::from(size)),
};
insert_entry(connection, size_entry)?;
let mime_entry = Entry {
entity: Address::Hash(file_hash.clone()),
attribute: FILE_MIME_KEY.to_string(),
value: EntryValue::Value(Value::String(tree_magic::from_filepath(&path))),
};
insert_entry(connection, mime_entry)?;
// Finally, add the appropriate entries w/r/t virtual filesystem location
let components = normalized_path.components().collect::<Vec<Component>>();
@ -313,6 +308,12 @@ fn _process_directory_entry<P: AsRef<Path>>(
let parent_dir = resolved_path.last().unwrap();
connection.transaction::<_, Error, _>(|| {
insert_file(connection, new_file)?;
insert_entry(connection, type_entry)?;
insert_entry(connection, size_entry)?;
insert_entry(connection, mime_entry)?;
let dir_has_entry = Entry {
entity: parent_dir.clone(),
attribute: HIER_HAS_ATTR.to_string(),