Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update of play count after removing tracks from history playlist #12258

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/library/dao/trackdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"),
Expand Down
21 changes: 21 additions & 0 deletions tools/mixxxdb_cleanup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
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 --
Expand Down
Loading