Now resolve the preferred artist artworks during scan steps

This commit is contained in:
emeric
2025-06-21 22:18:17 +02:00
parent 67db09685d
commit 93b446e124
10 changed files with 121 additions and 86 deletions
+7 -7
View File
@@ -21,9 +21,9 @@
#include <Wt/Dbo/WtSqlTraits.h>
#include "core/ILogger.hpp"
#include "database/Artwork.hpp"
#include "database/Cluster.hpp"
#include "database/Directory.hpp"
#include "database/Image.hpp"
#include "database/Release.hpp"
#include "database/Session.hpp"
#include "database/Track.hpp"
@@ -315,14 +315,14 @@ AND NOT EXISTS (
return getMBID().has_value();
}
ObjectPtr<Image> Artist::getImage() const
ObjectPtr<Artwork> Artist::getPreferredArtwork() const
{
return ObjectPtr<Image>{ _image };
return ObjectPtr<Artwork>{ _preferredArtwork };
}
ImageId Artist::getImageId() const
ArtworkId Artist::getPreferredArtworkId() const
{
return _image.id();
return _preferredArtwork.id();
}
RangeResults<ArtistId> Artist::findSimilarArtistIds(core::EnumSet<TrackArtistLinkType> artistLinkTypes, std::optional<Range> range) const
@@ -421,8 +421,8 @@ AND NOT EXISTS (
LMS_LOG(DB, WARNING, "Artist sort name too long, truncated to '" << _sortName << "'");
}
void Artist::setImage(ObjectPtr<Image> image)
void Artist::setPreferredArtwork(ObjectPtr<Artwork> artwork)
{
_image = getDboPtr(image);
_preferredArtwork = getDboPtr(artwork);
}
} // namespace lms::db
+24 -2
View File
@@ -1245,7 +1245,6 @@ FROM tracklist)");
"comment" text not null,
"preferred_artwork_id" bigint,
constraint "fk_release_preferred_artwork" foreign key ("preferred_artwork_id") references "artwork" ("id") on delete set null deferrable initially deferred))");
// Migrate data, with the new preferred_artwork_id field set to null
utils::executeCommand(*session.getDboSession(), R"(INSERT INTO release_backup
SELECT
@@ -1310,7 +1309,6 @@ FROM release)");
constraint "fk_track_preferred_artwork" foreign key ("preferred_artwork_id") references "artwork" ("id") on delete set null deferrable initially deferred,
constraint "fk_track_preferred_media_artwork" foreign key ("preferred_media_artwork_id") references "artwork" ("id") on delete set null deferrable initially deferred
))");
// Migrate data, with the new preferred_artwork_id and preferred_media_artwork_id fields set to null
utils::executeCommand(*session.getDboSession(), R"(INSERT INTO track_backup
SELECT
@@ -1354,6 +1352,30 @@ FROM track)");
utils::executeCommand(*session.getDboSession(), "DROP TABLE track");
utils::executeCommand(*session.getDboSession(), "ALTER TABLE track_backup RENAME TO track");
// Replaced image by artwork for artist
utils::executeCommand(*session.getDboSession(), R"(CREATE TABLE IF NOT EXISTS "artist_backup" (
"id" integer primary key autoincrement,
"version" integer not null,
"name" text not null,
"sort_name" text not null,
"mbid" text not null,
"preferred_artwork_id" bigint,
constraint "fk_artist_preferred_artwork" foreign key ("preferred_artwork_id") references "artwork" ("id") on delete set null deferrable initially deferred
))");
// Migrate data, with the new preferred_artwork_id field set to null
utils::executeCommand(*session.getDboSession(), R"(INSERT INTO artist_backup
SELECT
id,
version,
name,
sort_name,
mbid,
NULL as preferred_artwork_id
FROM artist)");
utils::executeCommand(*session.getDboSession(), "DROP TABLE artist");
utils::executeCommand(*session.getDboSession(), "ALTER TABLE artist_backup RENAME TO artist");
// Just increment the scan version of the settings to make the next scan rescan everything
utils::executeCommand(*session.getDboSession(), "UPDATE scan_settings SET audio_scan_version = audio_scan_version + 1");
}
-1
View File
@@ -198,7 +198,6 @@ namespace lms::db
{
auto transaction{ createWriteTransaction() };
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artist_id_idx ON artist(id)");
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artist_image_idx ON artist(image_id)");
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artist_name_mbid_idx ON artist(name, mbid)");
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artist_sort_name_nocase_idx ON artist(sort_name COLLATE NOCASE)");
utils::executeCommand(_session, "CREATE INDEX IF NOT EXISTS artist_mbid_idx ON artist(mbid)");