π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove unused asset progress metrics
Manav Rathi818aaf9614ed
diff --git a/rust/apps/ensu/src-tauri/src/commands/llm.rs b/rust/apps/ensu/src-tauri/src/commands/llm.rsindex 6ea3c29d56..124ea76bd2 100644--- a/rust/apps/ensu/src-tauri/src/commands/llm.rs+++ b/rust/apps/ensu/src-tauri/src/commands/llm.rs@@ -309,17 +309,17 @@ pub async fn llm_download_model(.download(std::slice::from_ref(&asset),|progress| {- let progress = ente_ensu::model::display_progress(&progress);- if let Some(line) = &progress.log_line {+ let display = ente_ensu::model::display_progress(&progress);+ if let Some(line) = &display.log_line {logging::log("LLMDownload", line.clone());}let _ = window.emit("llm-download-progress",DownloadProgress {- percent: progress.percent,- status: progress.status,- bytes_downloaded: progress.downloaded_bytes,- total_bytes: progress.total_bytes,+ percent: (progress.batch_percentage as i32).clamp(0, 99),+ status: display.status,+ bytes_downloaded: progress.batch_downloaded_bytes,+ total_bytes: progress.batch_total_bytes,},);},diff --git a/rust/bindings/uniffi/ensu/src/assets.rs b/rust/bindings/uniffi/ensu/src/assets.rsindex 24bd9e4846..fe9f6c4510 100644--- a/rust/bindings/uniffi/ensu/src/assets.rs+++ b/rust/bindings/uniffi/ensu/src/assets.rs@@ -97,11 +97,11 @@ impl From<ente_assets::AssetDownloadProgress> for AssetDownloadProgress {let display = ente_ensu::model::display_progress(&value);Self {label: value.asset_progress.label,- downloaded_bytes: i64::try_from(value.downloaded_bytes).unwrap_or(i64::MAX),+ downloaded_bytes: i64::try_from(value.batch_downloaded_bytes).unwrap_or(i64::MAX),total_bytes: value- .total_bytes+ .batch_total_bytes.map(|total| i64::try_from(total).unwrap_or(i64::MAX)),- percentage: value.percentage,+ percentage: value.batch_percentage,status: display.status,log_line: display.log_line,}diff --git a/rust/crates/assets/src/download.rs b/rust/crates/assets/src/download.rsindex 7959c1371e..1d14cb5196 100644--- a/rust/crates/assets/src/download.rs+++ b/rust/crates/assets/src/download.rs@@ -78,16 +78,10 @@ pub struct Progress {pub downloaded_bytes: u64,pub total_bytes: Option<u64>,pub file_downloaded_bytes: u64,- pub file_total_bytes: Option<u64>,- pub percentage: f64,- pub elapsed_ms: u64,- pub bytes_per_second: f64,pub file_elapsed_ms: u64,pub file_bytes_per_second: f64,- pub retry_count: u32,pub file_retry_count: u32,pub file_complete: bool,- pub complete: bool,}#[derive(Default)]@@ -265,7 +259,6 @@ async fn fetch_async(return Err(Error::Cancelled);}- let download_started_at = Instant::now();let mut download_probes = Vec::with_capacity(targets.len());let mut cached = Vec::with_capacity(targets.len());@@ -316,7 +309,6 @@ async fn fetch_async(.collect::<Vec<_>>();emit_progress(ProgressPhase::Preparing,- Duration::ZERO,total_bytes,&file_states,&mut on_progress,@@ -351,7 +343,6 @@ async fn fetch_async(index,complete: false,},- download_started_at.elapsed(),total_bytes,&file_states,&mut on_progress,@@ -382,7 +373,6 @@ async fn fetch_async(index,complete: true,},- download_started_at.elapsed(),total_bytes,&file_states,&mut on_progress,@@ -390,7 +380,6 @@ async fn fetch_async(}emit_progress(ProgressPhase::Complete,- download_started_at.elapsed(),total_bytes,&file_states,&mut on_progress,@@ -1301,7 +1290,6 @@ enum ProgressPhase<'a> {fn emit_progress<F: FnMut(Progress)>(phase: ProgressPhase,- elapsed: Duration,total_bytes: Option<u64>,file_states: &[FileProgress],on_progress: &mut F,@@ -1310,14 +1298,6 @@ fn emit_progress<F: FnMut(Progress)>(.iter().map(|state| state.downloaded_bytes).sum::<u64>();- let network_downloaded_bytes = file_states- .iter()- .map(|state| state.network_downloaded_bytes)- .sum::<u64>();- let retry_count = file_states- .iter()- .map(|state| state.retry_count)- .fold(0u32, u32::saturating_add);let file_state = match &phase {ProgressPhase::File { index, .. } => file_states.get(*index).copied(),_ => None,@@ -1333,40 +1313,27 @@ fn emit_progress<F: FnMut(Progress)>(}),};- let (label, file_complete, complete) = match phase {- ProgressPhase::Preparing => ("Preparing downloads", false, false),+ let (label, file_complete) = match phase {+ ProgressPhase::Preparing => ("Preparing downloads", false),ProgressPhase::File {label, complete, ..- } => (label, complete, false),- ProgressPhase::Complete => ("Complete", false, true),+ } => (label, complete),+ ProgressPhase::Complete => ("Complete", false),};- let percentage = total_bytes- .filter(|value| *value > 0)- .map(|total| ((downloaded_bytes as f64 / total as f64) * 100.0).clamp(0.0, 100.0))- .unwrap_or(0.0);- let (file_downloaded_bytes, file_total_bytes) = file_state- .map(|state| (state.downloaded_bytes, state.total_bytes))- .unwrap_or((0, None));on_progress(Progress {label: label.to_string(),downloaded_bytes,total_bytes,- file_downloaded_bytes,- file_total_bytes,- percentage,- elapsed_ms: duration_ms(elapsed),- bytes_per_second: bytes_per_second(network_downloaded_bytes, elapsed),+ file_downloaded_bytes: file_state.map(|state| state.downloaded_bytes).unwrap_or(0),file_elapsed_ms: file_state.map(|state| duration_ms(state.elapsed)).unwrap_or(0),file_bytes_per_second: file_state.map(|state| bytes_per_second(state.network_downloaded_bytes, state.elapsed)).unwrap_or(0.0),- retry_count,file_retry_count: file_state.map(|state| state.retry_count).unwrap_or(0),file_complete,- complete,});}diff --git a/rust/crates/assets/src/store.rs b/rust/crates/assets/src/store.rsindex 5ecd122b80..c3a3d2c567 100644--- a/rust/crates/assets/src/store.rs+++ b/rust/crates/assets/src/store.rs@@ -35,10 +35,11 @@ pub struct AssetFile {#[derive(Debug, Clone)]pub struct AssetDownloadProgress {+ pub asset_index: usize,pub asset_progress: Progress,- pub downloaded_bytes: u64,- pub total_bytes: Option<u64>,- pub percentage: f64,+ pub batch_downloaded_bytes: u64,+ pub batch_total_bytes: Option<u64>,+ pub batch_percentage: f64,}#[derive(Debug, thiserror::Error)]@@ -219,8 +220,7 @@ impl AssetStore {self.downloader()?.download(self.download_targets(asset),- |mut update| {- update.complete = false;+ |update| {progress.lock().expect("progress lock")@@ -388,17 +388,17 @@ wherefn update(&mut self, asset_index: usize, asset_progress: Progress) {self.pending[asset_index] = false;self.assets[asset_index] = Some(asset_progress.clone());- self.emit(asset_progress);+ self.emit(asset_index, asset_progress);}- fn emit(&mut self, asset_progress: Progress) {- let downloaded_bytes = self+ fn emit(&mut self, asset_index: usize, asset_progress: Progress) {+ let batch_downloaded_bytes = self.assets.iter().flatten().map(|progress| progress.downloaded_bytes).sum();- let total_bytes = (!self.pending.iter().any(|pending| *pending))+ let batch_total_bytes = (!self.pending.iter().any(|pending| *pending)).then(|| {self.assets.iter()@@ -407,15 +407,16 @@ where.try_fold(0u64, |total, value| total.checked_add(value?))}).flatten();- let percentage = total_bytes+ let batch_percentage = batch_total_bytes.filter(|total| *total > 0)- .map(|total| ((downloaded_bytes as f64 / total as f64) * 100.0).clamp(0.0, 100.0))+ .map(|total| ((batch_downloaded_bytes as f64 / total as f64) * 100.0).clamp(0.0, 100.0)).unwrap_or(0.0);(self.callback)(AssetDownloadProgress {+ asset_index,asset_progress,- downloaded_bytes,- total_bytes,- percentage,+ batch_downloaded_bytes,+ batch_total_bytes,+ batch_percentage,});}}@@ -599,15 +600,17 @@ mod tests {stage_files(&store, &first, &[("model", b"first")]);stage_files(&store, &second, &[("model", b"second")]);let mut latest_progress = None;+ let mut asset_progress = [0, 0];store.download(&[first.clone(), second.clone()],|progress| {+ asset_progress[progress.asset_index] = progress.asset_progress.downloaded_bytes;latest_progress = Some((- progress.downloaded_bytes,- progress.total_bytes,- progress.percentage,+ progress.batch_downloaded_bytes,+ progress.batch_total_bytes,+ progress.batch_percentage,));},CancellationToken::default(),@@ -617,6 +620,7 @@ mod tests {assert!(store.is_downloaded(&first));assert!(store.is_downloaded(&second));+ assert_eq!(asset_progress, [5, 6]);assert_eq!(latest_progress, Some((11, Some(11), 100.0)));let _ = fs::remove_dir_all(root);}diff --git a/rust/crates/ensu/src/model/mod.rs b/rust/crates/ensu/src/model/mod.rsindex 7aa51a0c4f..385cbe9ab0 100644--- a/rust/crates/ensu/src/model/mod.rs+++ b/rust/crates/ensu/src/model/mod.rs@@ -18,10 +18,7 @@ pub struct InvalidPreset {reason: String,}-pub struct ModelDownloadProgress {- pub downloaded_bytes: u64,- pub total_bytes: Option<u64>,- pub percent: i32,+pub struct ModelDownloadDisplay {pub status: String,pub log_line: Option<String>,}@@ -123,19 +120,19 @@ pub(crate) fn trimmed(value: Option<&str>) -> Option<&str> {value.map(str::trim).filter(|value| !value.is_empty())}-pub fn display_progress(progress: &AssetDownloadProgress) -> ModelDownloadProgress {- let total = progress.total_bytes.filter(|total| *total > 0);- let percent = total- .map(|total| ((progress.downloaded_bytes * 100 / total) as i32).clamp(0, 99))- .unwrap_or(0);+pub fn display_progress(progress: &AssetDownloadProgress) -> ModelDownloadDisplay {+ let total = progress.batch_total_bytes.filter(|total| *total > 0);let status = if let Some(total) = total {format!("Downloading... {} / {}",- format_bytes(progress.downloaded_bytes),+ format_bytes(progress.batch_downloaded_bytes),format_bytes(total))- } else if progress.downloaded_bytes > 0 {- format!("Downloading... {}", format_bytes(progress.downloaded_bytes))+ } else if progress.batch_downloaded_bytes > 0 {+ format!(+ "Downloading... {}",+ format_bytes(progress.batch_downloaded_bytes)+ )} else {"Downloading...".to_string()};@@ -153,13 +150,7 @@ pub fn display_progress(progress: &AssetDownloadProgress) -> ModelDownloadProgreNone};- ModelDownloadProgress {- downloaded_bytes: progress.downloaded_bytes,- total_bytes: progress.total_bytes,- percent,- status,- log_line,- }+ ModelDownloadDisplay { status, log_line }}fn invalid_preset(preset: &ModelPreset, reason: impl Into<String>) -> InvalidPreset {