Commit e2d32dd9 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

properly update album when removing one of its track

when an album is modified (tracks removed, ...) delay computing the
notification for the tracks of the album

after all modifications have been done, ensure all tracks within
modified albums are notified as modified (ensure for example that cover
changes are propagated to tracks)
parent 51689394
Pipeline #63003 passed with stage
in 27 seconds
......@@ -561,25 +561,7 @@ DataTypes::ListTrackDataType DatabaseInterface::albumData(qulonglong databaseId)
return result;
}
d->mSelectTrackQuery.bindValue(QStringLiteral(":albumId"), databaseId);
auto queryResult = execQuery(d->mSelectTrackQuery);
if (!queryResult || !d->mSelectTrackQuery.isSelect() || !d->mSelectTrackQuery.isActive()) {
Q_EMIT databaseError();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::albumData" << d->mSelectTrackQuery.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::albumData" << d->mSelectTrackQuery.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::albumData" << d->mSelectTrackQuery.lastError();
}
while (d->mSelectTrackQuery.next()) {
const auto &currentRecord = d->mSelectTrackQuery.record();
result.push_back(buildTrackDataFromDatabaseRecord(currentRecord));
}
d->mSelectTrackQuery.finish();
result = internalOneAlbumData(databaseId);
transactionResult = finishTransaction();
if (!transactionResult) {
......@@ -7129,7 +7111,6 @@ void DatabaseInterface::internalRemoveTracksList(const QList<QUrl> &removedTrack
if (modifiedAlbumId) {
recordModifiedAlbum(modifiedAlbumId);
modifiedAlbums.insert(modifiedAlbumId);
updateAlbumFromId(modifiedAlbumId, oneRemovedTrack.albumCover(), oneRemovedTrack, trackPath);
}
if (removedArtistId != 0 && allTracksFromArtist.isEmpty() && allAlbumsFromArtist.isEmpty()) {
......@@ -7160,6 +7141,13 @@ void DatabaseInterface::internalRemoveTracksList(const QList<QUrl> &removedTrack
auto tracksCount = fetchTrackIds(modifiedAlbumId).count();
if (!modifiedAlbumData.isEmpty() && tracksCount) {
auto modifiedAlbum = internalOneAlbumData(modifiedAlbumId);
if (updateAlbumFromId(modifiedAlbumId, modifiedAlbum.at(0).albumCover(), modifiedAlbum.at(0), modifiedAlbum.at(0).resourceURI().toString(currentOptions))) {
for (const auto &oneTrack : modifiedAlbum) {
recordModifiedTrack(oneTrack.databaseId());
}
}
Q_EMIT albumModified({{DataTypes::DatabaseIdRole, modifiedAlbumId}}, modifiedAlbumId);
} else {
removeAlbumInDatabase(modifiedAlbumId);
......@@ -8085,6 +8073,33 @@ DataTypes::ListAlbumDataType DatabaseInterface::internalAllAlbumsPartialData(QSq
return result;
}
DataTypes::ListTrackDataType DatabaseInterface::internalOneAlbumData(qulonglong databaseId)
{
DataTypes::ListTrackDataType result;
d->mSelectTrackQuery.bindValue(QStringLiteral(":albumId"), databaseId);
auto queryResult = execQuery(d->mSelectTrackQuery);
if (!queryResult || !d->mSelectTrackQuery.isSelect() || !d->mSelectTrackQuery.isActive()) {
Q_EMIT databaseError();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::albumData" << d->mSelectTrackQuery.lastQuery();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::albumData" << d->mSelectTrackQuery.boundValues();
qCDebug(orgKdeElisaDatabase) << "DatabaseInterface::albumData" << d->mSelectTrackQuery.lastError();
}
while (d->mSelectTrackQuery.next()) {
const auto &currentRecord = d->mSelectTrackQuery.record();
result.push_back(buildTrackDataFromDatabaseRecord(currentRecord));
}
d->mSelectTrackQuery.finish();
return result;
}
DataTypes::AlbumDataType DatabaseInterface::internalOneAlbumPartialData(qulonglong databaseId)
{
auto result = DataTypes::AlbumDataType{};
......
......@@ -255,6 +255,8 @@ private:
DataTypes::ListAlbumDataType internalAllAlbumsPartialData(QSqlQuery &query);
DataTypes::ListTrackDataType internalOneAlbumData(qulonglong databaseId);
DataTypes::AlbumDataType internalOneAlbumPartialData(qulonglong databaseId);
DataTypes::ArtistDataType internalOneArtistPartialData(qulonglong databaseId);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment