[db] fix clippy warnings

feat/vaults
Tomáš Mládek 2021-10-28 17:34:01 +02:00
parent 695a5e5aa9
commit 30189b42a5
2 changed files with 17 additions and 29 deletions

View File

@ -165,7 +165,7 @@ pub fn fetch_or_create_dir<C: Connection<Backend = Sqlite>>(
let parent = parent.unwrap_or_else(|| HIER_ROOT_INVARIANT_ADDR.clone());
let matching_directories: Vec<Address> = query(
let matching_directories = query(
connection,
Query::SingleQuery(QueryPart::Matches(EntryQuery {
entity: QueryComponent::Any,
@ -176,8 +176,7 @@ pub fn fetch_or_create_dir<C: Connection<Backend = Sqlite>>(
})),
)?
.into_iter()
.map(|e: Entry| e.entity)
.collect();
.map(|e: Entry| e.entity);
let parent_has: Vec<Address> = query(
connection,
@ -190,7 +189,6 @@ pub fn fetch_or_create_dir<C: Connection<Backend = Sqlite>>(
.extract_addresses();
let valid_directories: Vec<Address> = matching_directories
.into_iter()
.filter(|a| parent_has.contains(a))
.collect();
@ -286,7 +284,7 @@ mod tests {
]);
let str_path = path.to_string();
assert!(str_path.len() > 0);
assert!(!str_path.is_empty());
let decoded_path: Result<UPath> = str_path.parse();
assert!(decoded_path.is_ok());
@ -306,4 +304,3 @@ mod tests {
assert!(invalid_path.is_err());
}
}

View File

@ -174,20 +174,16 @@ fn _rescan_vault<T: AsRef<Path>>(
})
.collect();
let cleanup_results: Vec<UpdatePathResult> = existing_files
.write()
.unwrap()
.iter()
.filter(|f| f.valid)
.map(|file| {
let connection = pool.get()?;
connection.transaction::<_, Error, _>(|| {
file_set_valid(&connection, file.id, false)?;
// remove_object(&connection, )?
Ok(UpdatePathOutcome::Removed(PathBuf::from(file.path.clone())))
})
let existing_files = existing_files.read().unwrap();
let cleanup_results = existing_files.iter().filter(|f| f.valid).map(|file| {
let connection = pool.get()?;
connection.transaction::<_, Error, _>(|| {
file_set_valid(&connection, file.id, false)?;
// remove_object(&connection, )?
Ok(UpdatePathOutcome::Removed(PathBuf::from(file.path.clone())))
})
.collect();
});
let mut failed: Vec<&Error> = vec![];
let mut created = 0;
@ -226,10 +222,7 @@ fn _rescan_vault<T: AsRef<Path>>(
start.elapsed().as_secs()
);
Ok(path_results
.into_iter()
.chain(cleanup_results.into_iter())
.collect())
Ok(path_results.into_iter().chain(cleanup_results).collect())
}
fn _process_directory_entry<P: AsRef<Path>>(
@ -241,8 +234,8 @@ fn _process_directory_entry<P: AsRef<Path>>(
info!("Processing: {:?}", path);
// Prepare the data
let db_pool = Arc::clone(&db_pool);
let existing_files = Arc::clone(&existing_files);
let db_pool = Arc::clone(db_pool);
let existing_files = Arc::clone(existing_files);
let normalized_path = path.strip_prefix(&directory_path)?;
let normalized_path_str = normalized_path.to_str().expect("path not valid unicode?!");
@ -473,16 +466,14 @@ mod test {
rescan_result
.iter()
.filter(|upo| matches!(upo.as_ref().unwrap(), UpdatePathOutcome::Unchanged(_)))
.collect::<Vec<_>>()
.len()
.count()
);
assert_eq!(
1,
rescan_result
.iter()
.filter(|upo| matches!(upo.as_ref().unwrap(), UpdatePathOutcome::Removed(_)))
.collect::<Vec<_>>()
.len()
.count()
);
}
}