move all inserts into a single transaction
parent
dd765ee94b
commit
bc97b8bc8f
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue