From 13b89eddf9404ed74092ea48b9dca58d4f3439f5 Mon Sep 17 00:00:00 2001 From: Luke Stebner Date: Tue, 7 Jul 2026 21:13:13 -0700 Subject: [PATCH] fix: retry album art discovery for albums previously found to have none Albums where art extraction found nothing were permanently marked art_source = 'none' and never reconsidered by later scans, so a folder cover image added after the first scan was never picked up. Co-Authored-By: Claude Sonnet 5 --- src-tauri/src/db/queries/albums.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/db/queries/albums.rs b/src-tauri/src/db/queries/albums.rs index 4800fac..82a82f6 100644 --- a/src-tauri/src/db/queries/albums.rs +++ b/src-tauri/src/db/queries/albums.rs @@ -101,10 +101,13 @@ pub fn upsert( Ok(id) } -/// Albums that have never had art extraction attempted (`art_source` is -/// only ever NULL before the first attempt, then 'embedded'/'folder'/'none'). +/// Albums lacking cached art: never attempted (`art_source IS NULL`), or +/// previously attempted and found nothing (`art_source = 'none'`). The +/// latter must be retried on every scan rather than cached permanently, +/// since a folder cover image can be added to an album's directory after +/// it was first scanned. pub fn list_missing_art(conn: &Connection) -> Result, AppError> { - let mut stmt = conn.prepare("SELECT id FROM albums WHERE art_source IS NULL")?; + let mut stmt = conn.prepare("SELECT id FROM albums WHERE art_source IS NULL OR art_source = 'none'")?; let rows = stmt.query_map([], |row| row.get::<_, i64>(0))?; rows.collect::, _>>().map_err(AppError::from) } @@ -299,6 +302,23 @@ mod tests { assert_eq!(rows[0].art_path.as_deref(), Some("/cache/art/1.jpg")); } + #[test] + fn albums_previously_found_to_have_no_art_are_retried_on_the_next_scan() { + let conn = test_connection(); + let artist_id = artists::upsert(&conn, "Thrice").unwrap(); + let album_id = upsert(&conn, "Vheissu", artist_id, Some(2005)).unwrap(); + insert_active_track(&conn, "/music/vheissu.flac", artist_id, album_id); + + set_art(&conn, album_id, None, "none").unwrap(); + + assert_eq!( + list_missing_art(&conn).unwrap(), + vec![album_id], + "a cover image may have been added to the album folder since the last scan, so \ + albums with no art found previously must be re-checked rather than skipped forever" + ); + } + #[test] fn is_new_is_true_for_recently_added_unplayed_album() { let conn = test_connection();