performance improvements

This commit is contained in:
sreedev
2022-12-29 19:57:25 -05:00
parent e35072335e
commit efadfe6c8a
2 changed files with 14 additions and 10 deletions

View File

@@ -1,15 +1,17 @@
mod database;
mod scanner;
mod cli;
mod database;
mod output;
mod scanner;
use clap::Parser;
use anyhow::Result;
use clap::Parser;
#[tokio::main]
async fn main() -> Result<()> {
let connection = sqlite::open("/tmp/deduplicator.db")?;
database::setup(&connection)?;
let connection = sqlite::open("/tmp/deduplicator.db").and_then(|conn| {
database::setup(&conn).ok();
Ok(conn)
})?;
let duplicates = scanner::duplicates(cli::App::parse(), &connection)?;
output::print(duplicates);

View File

@@ -76,15 +76,17 @@ fn scan(app_opts: App, connection: &sqlite::Connection) -> Result<Vec<String>> {
}
fn index_files(files: Vec<String>, connection: &sqlite::Connection) {
files
.into_iter()
let hashed: Vec<File> = files
.into_par_iter()
.map(|file| {
let hash = hash_file(&file).unwrap();
database::File { path: file, hash }
})
.for_each(|file| {
database::put(&file, connection).unwrap();
});
.collect();
hashed.into_iter().for_each(|file| {
database::put(&file, connection).unwrap();
});
}
pub fn hash_file(filepath: &str) -> Result<String> {