From 26d8fb502cba125c54b576f1c510acb46e511cab Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 23 Feb 2026 02:42:03 -0600 Subject: [PATCH] feat(backend): add bulk fetch for custom artist images Add get_all_custom_artist_images() database method and v2_library_get_all_custom_artist_images command to support loading all custom artist image overrides at once for the global resolution store. --- crates/qbz-library/src/database.rs | 28 ++++++++++++++++++++++++++++ src-tauri/src/commands_v2.rs | 9 +++++++++ src-tauri/src/lib.rs | 1 + 3 files changed, 38 insertions(+) diff --git a/crates/qbz-library/src/database.rs b/crates/qbz-library/src/database.rs index 52d05f33a..903b93876 100644 --- a/crates/qbz-library/src/database.rs +++ b/crates/qbz-library/src/database.rs @@ -3457,6 +3457,34 @@ impl LibraryDatabase { Ok(result) } + /// Get all custom artist images (for bulk lookup) + pub fn get_all_custom_artist_images( + &self, + ) -> Result, LibraryError> { + let mut stmt = self + .conn + .prepare( + "SELECT artist_name, custom_image_path FROM artist_images WHERE custom_image_path IS NOT NULL", + ) + .map_err(|e| LibraryError::Database(format!("Failed to prepare query: {}", e)))?; + + let rows = stmt + .query_map([], |row| { + Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?)) + }) + .map_err(|e| { + LibraryError::Database(format!("Failed to query custom artist images: {}", e)) + })?; + + let mut map = std::collections::HashMap::new(); + for row in rows { + if let Ok((artist_name, custom_image_path)) = row { + map.insert(artist_name, custom_image_path); + } + } + Ok(map) + } + /// Get all canonical artist names mapping (for bulk lookup) pub fn get_all_canonical_names( &self, diff --git a/src-tauri/src/commands_v2.rs b/src-tauri/src/commands_v2.rs index 56328a424..28f451c37 100644 --- a/src-tauri/src/commands_v2.rs +++ b/src-tauri/src/commands_v2.rs @@ -4337,6 +4337,15 @@ pub async fn v2_library_get_artist_image( db.get_artist_image(&artist_name).map_err(|e| e.to_string()) } +#[tauri::command] +pub async fn v2_library_get_all_custom_artist_images( + state: State<'_, LibraryState>, +) -> Result, String> { + let guard = state.db.lock().await; + let db = guard.as_ref().ok_or("No active session - please log in")?; + db.get_all_custom_artist_images().map_err(|e| e.to_string()) +} + #[tauri::command] pub async fn v2_create_artist_radio( artist_id: u64, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 10832c50f..fb131dd02 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -904,6 +904,7 @@ pub fn run() { commands_v2::v2_library_set_custom_artist_image, commands_v2::v2_library_remove_custom_artist_image, commands_v2::v2_library_get_artist_image, + commands_v2::v2_library_get_all_custom_artist_images, commands_v2::v2_show_track_notification, commands_v2::v2_subscribe_playlist, commands_v2::v2_cache_track_for_offline,