From 392085b7657d576422c1b88e9d38d0d7e52069ca Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sat, 4 Nov 2023 17:44:47 +0100 Subject: [PATCH 1/2] Fix update of play count after removing tracks from history playlist --- src/library/dao/trackdao.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/library/dao/trackdao.cpp b/src/library/dao/trackdao.cpp index d2c06ce613c..e343ecfdd59 100644 --- a/src/library/dao/trackdao.cpp +++ b/src/library/dao/trackdao.cpp @@ -2252,7 +2252,7 @@ bool TrackDAO::updatePlayCounterFromPlayedHistory( VERIFY_OR_DEBUG_ASSERT(!trackIds.isEmpty()) { return false; } - // Update both timesplay and last_played_at according to the + // Update both timesplayed and last_played_at according to the // corresponding aggregated properties from the played history, // i.e. COUNT for the number of times a track has been played // and MAX for the last time it has been played. @@ -2302,13 +2302,13 @@ bool TrackDAO::updatePlayCounterFromPlayedHistory( "UPDATE library SET " "timesplayed=0," "last_played_at=NULL " - "WHERE library.id NOT IN(" + "WHERE id NOT IN(" "SELECT PlaylistTracks.track_id " "FROM PlaylistTracks " "JOIN Playlists ON " "PlaylistTracks.playlist_id=Playlists.id " - "WHERE Playlists.hidden=:playlistHidden " - "AND PlaylistTracks.track_id IN (%1))") + "WHERE Playlists.hidden=:playlistHidden) " + "AND id IN (%1)") .arg(trackIdList)); updateNotPlayed.bindValue( QStringLiteral(":playlistHidden"), From c08bf330beb6282fff6591ba5457b014e086f76f Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sat, 4 Nov 2023 19:02:21 +0100 Subject: [PATCH 2/2] Add SQL statement for restoring play counts to mixxxdb_cleanup.sql --- tools/mixxxdb_cleanup.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/mixxxdb_cleanup.sql b/tools/mixxxdb_cleanup.sql index a99a2676c78..f69d87d013d 100644 --- a/tools/mixxxdb_cleanup.sql +++ b/tools/mixxxdb_cleanup.sql @@ -47,6 +47,27 @@ DELETE FROM PlaylistTracks WHERE track_id NOT IN (SELECT id FROM library); -- Analysis DELETE FROM track_analysis WHERE track_id NOT IN (SELECT id FROM track_locations); +----------------------------------------------------------------------- +-- Restore the play count columns in the library table from the -- +-- history playlists (requires SQLite v3.33.0 or newer) -- +----------------------------------------------------------------------- + +UPDATE library +SET timesplayed=q.timesplayed,last_played_at=q.last_played_at +FROM ( + SELECT + PlaylistTracks.track_id as id, + COUNT(PlaylistTracks.track_id) as timesplayed, + MAX(PlaylistTracks.pl_datetime_added) as last_played_at + FROM PlaylistTracks + JOIN Playlists + ON PlaylistTracks.playlist_id=Playlists.id + -- PlaylistDAO::PLHT_SET_LOG=2 + WHERE Playlists.hidden=2 + GROUP BY PlaylistTracks.track_id +) q +WHERE library.id=q.id; + ----------------------------------------------------------------------- -- Fix referential integrity issues in external libraries (optional) -- -- Enable conditionally depending on the contents of mixxxdb.sqlite --