mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-09-07 02:24:24 +00:00
performance improvements
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -1,15 +1,17 @@
|
|||||||
mod database;
|
|
||||||
mod scanner;
|
|
||||||
mod cli;
|
mod cli;
|
||||||
|
mod database;
|
||||||
mod output;
|
mod output;
|
||||||
|
mod scanner;
|
||||||
|
|
||||||
use clap::Parser;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let connection = sqlite::open("/tmp/deduplicator.db")?;
|
let connection = sqlite::open("/tmp/deduplicator.db").and_then(|conn| {
|
||||||
database::setup(&connection)?;
|
database::setup(&conn).ok();
|
||||||
|
Ok(conn)
|
||||||
|
})?;
|
||||||
|
|
||||||
let duplicates = scanner::duplicates(cli::App::parse(), &connection)?;
|
let duplicates = scanner::duplicates(cli::App::parse(), &connection)?;
|
||||||
output::print(duplicates);
|
output::print(duplicates);
|
||||||
|
|||||||
@@ -76,15 +76,17 @@ fn scan(app_opts: App, connection: &sqlite::Connection) -> Result<Vec<String>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn index_files(files: Vec<String>, connection: &sqlite::Connection) {
|
fn index_files(files: Vec<String>, connection: &sqlite::Connection) {
|
||||||
files
|
let hashed: Vec<File> = files
|
||||||
.into_iter()
|
.into_par_iter()
|
||||||
.map(|file| {
|
.map(|file| {
|
||||||
let hash = hash_file(&file).unwrap();
|
let hash = hash_file(&file).unwrap();
|
||||||
database::File { path: file, hash }
|
database::File { path: file, hash }
|
||||||
})
|
})
|
||||||
.for_each(|file| {
|
.collect();
|
||||||
database::put(&file, connection).unwrap();
|
|
||||||
});
|
hashed.into_iter().for_each(|file| {
|
||||||
|
database::put(&file, connection).unwrap();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_file(filepath: &str) -> Result<String> {
|
pub fn hash_file(filepath: &str) -> Result<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user