Skip to content

Commit

Permalink
Merge pull request #12494 from ronso0/history-fix
Browse files Browse the repository at this point in the history
fix/History: remove obsolete placeholder playlists
  • Loading branch information
daschuer committed Jan 2, 2024
2 parents 17fd47b + 8b79278 commit b32ffd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/library/dao/playlistdao.cpp
Expand Up @@ -521,6 +521,9 @@ int PlaylistDAO::getPlaylistId(const int index) const {
PlaylistDAO::HiddenType PlaylistDAO::getHiddenType(const int playlistId) const {
// qDebug() << "PlaylistDAO::getHiddenType"
// << QThread::currentThread() << m_database.connectionName();
if (playlistId != kInvalidPlaylistId) { // type is known, save a query
return PlaylistDAO::PLHT_UNKNOWN;
}

QSqlQuery query(m_database);
query.prepare(QStringLiteral(
Expand All @@ -534,8 +537,8 @@ PlaylistDAO::HiddenType PlaylistDAO::getHiddenType(const int playlistId) const {
} else {
LOG_FAILED_QUERY(query);
}
qDebug() << "PlaylistDAO::getHiddenType returns PLHT_UNKNOWN for playlistId "
<< playlistId;
// qDebug() << "PlaylistDAO::getHiddenType returns PLHT_UNKNOWN for playlist"
// << playlistId << getPlaylistName(playlistId);
return PLHT_UNKNOWN;
}

Expand Down Expand Up @@ -1078,7 +1081,7 @@ void PlaylistDAO::shuffleTracks(const int playlistId,
QList<int> newPositions = positions;
const int searchDistance = math_max(static_cast<int>(trackPositionIds.count()) / 4, 1);

qDebug() << "Shuffling Tracks";
qDebug() << "Shuffling tracks of playlist" << playlistId << getPlaylistName(playlistId);
qDebug() << "*** Search Distance: " << searchDistance;
//for (int z = 0; z < positions.count(); z++) {
//qDebug() << "*** Position: " << positions[z] << " | ID: " << allIds.value(positions[z]);
Expand Down
16 changes: 14 additions & 2 deletions src/library/trackset/setlogfeature.cpp
Expand Up @@ -44,8 +44,18 @@ SetlogFeature::SetlogFeature(
// remove unneeded entries
deleteAllUnlockedPlaylistsWithFewerTracks();

// Create empty placeholder playlist for YEAR items
QString placeholderName = "historyPlaceholder";
// remove previously created placeholder playlists
const QList<QPair<int, QString>> pls = m_playlistDao.getPlaylists(PlaylistDAO::PLHT_UNKNOWN);
QStringList plsToDelete;
for (const QPair<int, QString>& pl : pls) {
if (pl.second.startsWith(placeholderName)) {
plsToDelete.append(QString::number(pl.first));
}
}
m_playlistDao.deletePlaylists(plsToDelete);

// Create empty placeholder playlist for YEAR items
m_yearNodeId = m_playlistDao.createUniquePlaylist(&placeholderName,
PlaylistDAO::PLHT_UNKNOWN);
DEBUG_ASSERT(m_yearNodeId != kInvalidPlaylistId);
Expand Down Expand Up @@ -98,8 +108,10 @@ SetlogFeature::SetlogFeature(

SetlogFeature::~SetlogFeature() {
// Clean up history when shutting down in case the track threshold changed,
// incl. the empty placeholder playlist and potentially empty current playlist
// incl. potentially empty current playlist
deleteAllUnlockedPlaylistsWithFewerTracks();
// Delete the placeholder
m_playlistDao.deletePlaylist(m_yearNodeId);
}

QVariant SetlogFeature::title() {
Expand Down

0 comments on commit b32ffd4

Please sign in to comment.