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.
This commit is contained in:
1 parent
88fe564802
commit
03736ef8f2
2 files changed
+29
-8
No files matched your search
@@ -1149,12 +1149,23 @@ pub async fn library_search(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn library_get_stats(state: State<'_, LibraryState>) -> Result<LibraryStats, String> {
|
||||
pub async fn library_get_stats(
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, crate::config::DownloadSettingsState>,
|
||||
) -> Result<LibraryStats, String> {
|
||||
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]
|
||||
|
||||
@@ -1596,11 +1596,15 @@ impl LibraryDatabase {
|
||||
}
|
||||
|
||||
/// Get library statistics
|
||||
pub fn get_stats(&self) -> Result<LibraryStats, LibraryError> {
|
||||
let mut stmt = self
|
||||
.conn
|
||||
.prepare(
|
||||
r#"
|
||||
pub fn get_stats(&self, include_qobuz_downloads: bool) -> Result<LibraryStats, LibraryError> {
|
||||
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| {
|
||||
|
||||
Reference in new issue
Block a user