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/History: remove obsolete placeholder playlists #12494

Merged
merged 2 commits into from Jan 2, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/library/dao/playlistdao.cpp
Expand Up @@ -520,6 +520,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 @@ -533,8 +536,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 @@ -1077,7 +1080,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 @@ -43,8 +43,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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto above and second here is not well readable.
Not your fault. If you have the mood to improve it go ahead.
Else we can ignore it in this bufix PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, auto was simply faster to type.
I'll change it.

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 @@ -97,8 +107,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