move all reimport db writes into a transaction
parent
e0a03b30fa
commit
9823f646cd
|
@ -5,7 +5,7 @@ use crate::database::{
|
||||||
};
|
};
|
||||||
use crate::hash::{ComputeHash, HasherWorker};
|
use crate::hash::{ComputeHash, HasherWorker};
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Error, Result};
|
||||||
use log::{error, info, trace};
|
use log::{error, info, trace};
|
||||||
use serde::export::Formatter;
|
use serde::export::Formatter;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
@ -363,25 +363,6 @@ async fn _process_directory_entry<C: Connection<Backend = Sqlite>, P: AsRef<Path
|
||||||
.collect::<Vec<Component>>();
|
.collect::<Vec<Component>>();
|
||||||
let (filename, dir_path) = components.split_last().unwrap();
|
let (filename, dir_path) = components.split_last().unwrap();
|
||||||
|
|
||||||
let file_address = Address::UUID(Uuid::new_v4());
|
|
||||||
|
|
||||||
let name_entry = InnerEntry {
|
|
||||||
target: file_address.clone(),
|
|
||||||
key: FILENAME_KEY.to_string(),
|
|
||||||
value: EntryValue::Value(Value::String(
|
|
||||||
filename.as_os_str().to_string_lossy().to_string(),
|
|
||||||
)),
|
|
||||||
};
|
|
||||||
let _ = insert_entry(connection, name_entry)?;
|
|
||||||
|
|
||||||
let identity_entry = InnerEntry {
|
|
||||||
target: file_address.clone(),
|
|
||||||
key: FILE_IDENTITY_KEY.to_string(),
|
|
||||||
value: EntryValue::Address(Address::Hash(digest.clone())),
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = insert_entry(connection, identity_entry)?;
|
|
||||||
|
|
||||||
let upath = UPath(
|
let upath = UPath(
|
||||||
iter::once(UDirectory {
|
iter::once(UDirectory {
|
||||||
name: "NATIVE".to_string(),
|
name: "NATIVE".to_string(),
|
||||||
|
@ -393,14 +374,36 @@ async fn _process_directory_entry<C: Connection<Backend = Sqlite>, P: AsRef<Path
|
||||||
);
|
);
|
||||||
let resolved_path = resolve_path(connection, &upath, true).await?;
|
let resolved_path = resolve_path(connection, &upath, true).await?;
|
||||||
let parent_dir = resolved_path.last().unwrap();
|
let parent_dir = resolved_path.last().unwrap();
|
||||||
let dir_has_entry = InnerEntry {
|
|
||||||
target: parent_dir.clone(),
|
|
||||||
key: DIR_HAS_KEY.to_string(),
|
|
||||||
value: EntryValue::Address(file_address),
|
|
||||||
};
|
|
||||||
let _ = insert_entry(connection, dir_has_entry)?;
|
|
||||||
|
|
||||||
Ok(())
|
connection.transaction::<_, Error, _>(|| {
|
||||||
|
let file_address = Address::UUID(Uuid::new_v4());
|
||||||
|
|
||||||
|
let name_entry = InnerEntry {
|
||||||
|
target: file_address.clone(),
|
||||||
|
key: FILENAME_KEY.to_string(),
|
||||||
|
value: EntryValue::Value(Value::String(
|
||||||
|
filename.as_os_str().to_string_lossy().to_string(),
|
||||||
|
)),
|
||||||
|
};
|
||||||
|
let _ = insert_entry(connection, name_entry)?;
|
||||||
|
|
||||||
|
let identity_entry = InnerEntry {
|
||||||
|
target: file_address.clone(),
|
||||||
|
key: FILE_IDENTITY_KEY.to_string(),
|
||||||
|
value: EntryValue::Address(Address::Hash(digest.clone())),
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = insert_entry(connection, identity_entry)?;
|
||||||
|
|
||||||
|
let dir_has_entry = InnerEntry {
|
||||||
|
target: parent_dir.clone(),
|
||||||
|
key: DIR_HAS_KEY.to_string(),
|
||||||
|
value: EntryValue::Address(file_address),
|
||||||
|
};
|
||||||
|
let _ = insert_entry(connection, dir_has_entry)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in New Issue