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.
This commit is contained in:
3 files changed
+38
No files matched your search
@@ -3457,6 +3457,34 @@ impl LibraryDatabase {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get all custom artist images (for bulk lookup)
|
||||||
|
pub fn get_all_custom_artist_images(
|
||||||
|
&self,
|
||||||
|
) -> Result<std::collections::HashMap<String, String>, 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)
|
/// Get all canonical artist names mapping (for bulk lookup)
|
||||||
pub fn get_all_canonical_names(
|
pub fn get_all_canonical_names(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -4337,6 +4337,15 @@ pub async fn v2_library_get_artist_image(
|
|||||||
db.get_artist_image(&artist_name).map_err(|e| e.to_string())
|
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<std::collections::HashMap<String, String>, 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]
|
#[tauri::command]
|
||||||
pub async fn v2_create_artist_radio(
|
pub async fn v2_create_artist_radio(
|
||||||
artist_id: u64,
|
artist_id: u64,
|
||||||
|
|||||||
@@ -906,6 +906,7 @@ pub fn run() {
|
|||||||
commands_v2::v2_library_set_custom_artist_image,
|
commands_v2::v2_library_set_custom_artist_image,
|
||||||
commands_v2::v2_library_remove_custom_artist_image,
|
commands_v2::v2_library_remove_custom_artist_image,
|
||||||
commands_v2::v2_library_get_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_show_track_notification,
|
||||||
commands_v2::v2_subscribe_playlist,
|
commands_v2::v2_subscribe_playlist,
|
||||||
commands_v2::v2_cache_track_for_offline,
|
commands_v2::v2_cache_track_for_offline,
|
||||||
|
|||||||
Reference in new issue
Block a user