From 31ece8fb88194a7d3884b85cd0064d2e0000f70b Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Mon, 20 May 2024 10:07:00 +0800 Subject: [PATCH 1/2] refactor: Remove commented out code and update return type in deep_scan --- src-tauri/src/app.rs | 69 +++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 401b0201..638ce519 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -9,6 +9,7 @@ use tauri::{State, Window}; use crate::dirstat::{DiskItem, DiskItemMetadata, FileInfo}; use crate::metrics::Metrics; use crate::models::*; +use rayon::prelude::*; pub struct AppState(Arc>); @@ -132,40 +133,62 @@ pub fn delete_folder(path: String) { } // Result, String> + #[tauri::command] -pub async fn deep_scan(path: String) -> Result, String> { +pub async fn deep_scan(path: String) -> Result { + let time = std::time::Instant::now(); dbg!("Scanning folder:", &path); let path_buf = PathBuf::from(&path); let file_info = FileInfo::from_path(&path_buf, true).map_err(|e| e.to_string())?; let analysed = match file_info { FileInfo::Directory { volume_id } => { - let sub_entries = fs::read_dir(path_buf) - .map_err(|e| e.to_string())? - .filter_map(Result::ok) - .collect::>(); - - let mut sub_items = sub_entries - .par_iter() - .filter_map(|entry| DiskItem::from_analyze(&entry.path(), true, volume_id).ok()) - .collect::>(); - - sub_items.sort_unstable_by(|a, b| a.metadata.size.cmp(&b.metadata.size).reverse()); - - sub_items + DiskItem::from_analyze(&path_buf, true, volume_id).map_err(|e| e.to_string())? } - FileInfo::File { size, .. } => vec![DiskItem { - name: path_buf - .file_name() - .unwrap_or(OsStr::new(".")) - .to_string_lossy() - .to_string(), - metadata: DiskItemMetadata { size }, - children: None, - }], + _ => return Err("Not a directory".into()), }; dbg!("Scanning complete"); + dbg!("Time taken:", time.elapsed().as_secs_f32()); Ok(analysed) } + +// #[tauri::command] 355.9603 seconds +// pub async fn deep_scan(path: String) -> Result, String> { +// let time = std::time::Instant::now(); +// dbg!("Scanning folder:", &path); +// let path_buf = PathBuf::from(&path); +// let file_info = FileInfo::from_path(&path_buf, true).map_err(|e| e.to_string())?; + +// let analysed = match file_info { +// FileInfo::Directory { volume_id } => { +// let sub_entries = fs::read_dir(path_buf) +// .map_err(|e| e.to_string())? +// .filter_map(Result::ok) +// .collect::>(); + +// let mut sub_items = sub_entries +// .par_iter() // Use rayon's parallel iterator +// .filter_map(|entry| DiskItem::from_analyze(&entry.path(), true, volume_id).ok()) +// .collect::>(); + +// sub_items.sort_unstable_by(|a, b| a.metadata.size.cmp(&b.metadata.size).reverse()); + +// sub_items +// } +// FileInfo::File { size, .. } => vec![DiskItem { +// name: path_buf +// .file_name() +// .unwrap_or(OsStr::new(".")) +// .to_string_lossy() +// .to_string(), +// metadata: DiskItemMetadata { size }, +// children: None, +// }], +// }; + +// dbg!("Scanning complete"); +// dbg!("Time taken:", time.elapsed().as_secs_f32()); +// Ok(analysed) +// } From 207f8c978e23ad71379be3d81ff9cc6a08eaada9 Mon Sep 17 00:00:00 2001 From: pacholoamit Date: Mon, 20 May 2024 10:07:54 +0800 Subject: [PATCH 2/2] fix: Update version to 0.9.1 --- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6c199884..f6a5d823 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -81,7 +81,7 @@ checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" [[package]] name = "app" -version = "0.9.0" +version = "0.9.1" dependencies = [ "chrono", "cocoa 0.25.0", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index f29996b0..7e40057a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.9.0" +version = "0.9.1" description = "Cross-platform (Linux, WIndows, MacOS) Desktop GUI system monitor" authors = ["Pacholo Amit"] license = "MIT" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 69d085d3..2d2dcfed 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "pachtop", - "version": "0.9.0" + "version": "0.9.1" }, "tauri": { "systemTray": {