fix(history): prune Most Played on folder removal; GC stale radio sessions

Removing a library folder pruned Recently Played but not
album_play_history.db, so Most Played kept cards onto deleted tracks.
radio_history had no delete path at all; sessions idle for more than
30 days (by last played_at, so a running radio is never pulled) are
dropped on open.

cc
This commit is contained in:
vicrodh committed 2026-08-28 19:54:47 -06:00
1 parent 6a99539537
commit 6ca219d90e
3 files changed
+83

No files matched your search

@@ -260,6 +260,36 @@ pub fn all_albums() -> Vec<AlbumPlayRow> {
with_db(|conn| Some(query_on(conn, None))).unwrap_or_default()
}
/// Drop every trace of the given albums — the twin of
/// `playlist_play_history::prune_playlists`, for albums whose library folder
/// was removed. Until this existed "Most Played Albums" kept cards that
/// opened onto deleted tracks while Recently Played had already pruned them.
/// Returns how many meta rows went.
pub fn prune_albums(album_ids: &[String]) -> usize {
if album_ids.is_empty() {
return 0;
}
with_db(|conn| Some(prune_on(conn, album_ids)))
.unwrap_or(0)
}
fn prune_on(conn: &Connection, album_ids: &[String]) -> usize {
let mut gone = 0usize;
for id in album_ids {
let _ = conn.execute(
"DELETE FROM album_play_events WHERE album_id = ?",
rusqlite::params![id],
);
gone += conn
.execute(
"DELETE FROM album_meta WHERE album_id = ?",
rusqlite::params![id],
)
.unwrap_or(0);
}
gone
}
#[cfg(test)]
mod tests {
use super::*;