From 03736ef8f2aab46161d17bd0b38c5a1c648dd6ae Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 6 Feb 2026 00:30:24 -0600 Subject: [PATCH] exclude qobuz_download tracks from library stats when toggle is off get_stats() now respects the show_in_library setting so offline cached tracks don't inflate the Local Library counter when the user has chosen not to show them there. --- src-tauri/src/library/commands.rs | 15 +++++++++++++-- src-tauri/src/library/database.rs | 22 ++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/library/commands.rs b/src-tauri/src/library/commands.rs index 968cd5ddc..6ec573eee 100644 --- a/src-tauri/src/library/commands.rs +++ b/src-tauri/src/library/commands.rs @@ -1149,12 +1149,23 @@ pub async fn library_search( } #[tauri::command] -pub async fn library_get_stats(state: State<'_, LibraryState>) -> Result { +pub async fn library_get_stats( + state: State<'_, LibraryState>, + download_settings_state: State<'_, crate::config::DownloadSettingsState>, +) -> Result { log::info!("Command: library_get_stats"); + let include_qobuz = download_settings_state + .lock() + .map_err(|e| format!("Failed to lock download settings: {}", e))? + .as_ref() + .and_then(|s| s.get_settings().ok()) + .map(|s| s.show_in_library) + .unwrap_or(false); + let guard__ = state.db.lock().await; let db = guard__.as_ref().ok_or("No active session - please log in")?; - db.get_stats().map_err(|e| e.to_string()) + db.get_stats(include_qobuz).map_err(|e| e.to_string()) } #[tauri::command] diff --git a/src-tauri/src/library/database.rs b/src-tauri/src/library/database.rs index b005b2ca8..6bacdfc6f 100644 --- a/src-tauri/src/library/database.rs +++ b/src-tauri/src/library/database.rs @@ -1596,11 +1596,15 @@ impl LibraryDatabase { } /// Get library statistics - pub fn get_stats(&self) -> Result { - let mut stmt = self - .conn - .prepare( - r#" + pub fn get_stats(&self, include_qobuz_downloads: bool) -> Result { + let source_filter = if include_qobuz_downloads { + "" + } else { + "WHERE (source IS NULL OR source != 'qobuz_download')" + }; + + let sql = format!( + r#" SELECT COUNT(*) as track_count, COUNT(DISTINCT COALESCE(album_group_key, album || '|' || COALESCE(album_artist, artist))) as album_count, @@ -1608,8 +1612,14 @@ impl LibraryDatabase { COALESCE(SUM(duration_secs), 0) as total_duration, COALESCE(SUM(file_size_bytes), 0) as total_size FROM local_tracks + {} "#, - ) + source_filter + ); + + let mut stmt = self + .conn + .prepare(&sql) .map_err(|e| LibraryError::Database(e.to_string()))?; stmt.query_row([], |row| {