Changed the way album covers are associated, fixes #503

This commit is contained in:
emeric
2024-09-29 16:21:46 +02:00
parent 4e1b422e31
commit 3f6177cedd
31 changed files with 502 additions and 231 deletions
-1
View File
@@ -379,5 +379,4 @@ namespace lms::db
{
_image = getDboPtr(image);
}
} // namespace lms::db
+2 -1
View File
@@ -23,6 +23,7 @@
#include "database/Artist.hpp"
#include "database/Directory.hpp"
#include "database/Release.hpp"
#include "database/Session.hpp"
#include "IdTypeTraits.hpp"
@@ -40,7 +41,7 @@ namespace lms::db
if (params.directory.isValid())
query.where("i.directory_id = ?").bind(params.directory);
if (!params.fileStem.empty())
query.where("i.stem = ?").bind(params.fileStem);
query.where("i.stem = ? COLLATE NOCASE").bind(params.fileStem);
return query;
}
+50 -1
View File
@@ -35,7 +35,7 @@ namespace lms::db
{
namespace
{
static constexpr Version LMS_DATABASE_VERSION{ 67 };
static constexpr Version LMS_DATABASE_VERSION{ 68 };
}
VersionInfo::VersionInfo()
@@ -761,6 +761,54 @@ SELECT
session.getDboSession()->execute("ALTER TABLE user DROP COLUMN cur_playing_track_pos");
}
void migrateFromV67(Session& session)
{
// Add a ref to release in image
session.getDboSession()->execute(R"(CREATE TABLE "image_backup" (
"id" integer primary key autoincrement,
"version" integer not null,
"absolute_file_path" text not null,
"stem" text not null,
"file_last_write" text,
"file_size" integer not null,
"width" integer not null,
"height" integer not null,
"artist_id" bigint,
"release_id" bigint,
"directory_id" bigint,
constraint "fk_image_artist" foreign key ("artist_id") references "artist" ("id") on delete cascade deferrable initially deferred,
constraint "fk_image_release" foreign key ("release_id") references "release" ("id") on delete cascade deferrable initially deferred,
constraint "fk_image_directory" foreign key ("directory_id") references "directory" ("id") on delete cascade deferrable initially deferred
))");
// Migrate data, with the new release_id field set to null
session.getDboSession()->execute(R"(INSERT INTO image_backup
SELECT
id,
version,
absolute_file_path,
stem,
file_last_write,
file_size,
width,
height,
artist_id,
NULL,
directory_id
FROM image
)");
session.getDboSession()->execute("DROP TABLE image");
session.getDboSession()->execute("ALTER TABLE image_backup RENAME TO image");
// Changed some indexes for the image table -> remove all the previoulsy created index, the createIndexesIfNeeded will recreate them all
std::vector<std::string> indexeNames{ utils::fetchQueryResults(session.getDboSession()->query<std::string>(R"(SELECT name FROM sqlite_master WHERE type = 'index' AND name LIKE '%_idx')")) };
for (const auto& indexName : indexeNames)
session.getDboSession()->execute("DROP INDEX " + indexName);
// Just increment the scan version of the settings to make the next scheduled scan rescan everything
session.getDboSession()->execute("UPDATE scan_settings SET scan_version = scan_version + 1");
}
bool doDbMigration(Session& session)
{
static const std::string outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
@@ -804,6 +852,7 @@ SELECT
{ 64, migrateFromV64 },
{ 65, migrateFromV65 },
{ 66, migrateFromV66 },
{ 67, migrateFromV67 },
};
bool migrationPerformed{};
+12 -1
View File
@@ -24,6 +24,8 @@
#include "core/ILogger.hpp"
#include "database/Artist.hpp"
#include "database/Cluster.hpp"
#include "database/Directory.hpp"
#include "database/Image.hpp"
#include "database/Session.hpp"
#include "database/Track.hpp"
#include "database/User.hpp"
@@ -540,6 +542,11 @@ namespace lms::db
return utils::fetchQueryResults<Release::pointer>(query);
}
ObjectPtr<Image> Release::getImage() const
{
return ObjectPtr<Image>{ _image.lock() };
}
void Release::clearLabels()
{
_labels.clear();
@@ -560,6 +567,11 @@ namespace lms::db
_releaseTypes.insert(getDboPtr(releaseType));
}
void Release::setImage(ObjectPtr<Image> image)
{
_image = getDboPtr(image);
}
bool Release::hasVariousArtists() const
{
// TODO optimize
@@ -665,5 +677,4 @@ namespace lms::db
return res;
}
} // namespace lms::db
+3 -2
View File
@@ -196,10 +196,11 @@ namespace lms::db
_session.execute("CREATE INDEX IF NOT EXISTS directory_media_library_idx ON directory(media_library_id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_artist_idx ON image(artist_id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_directory_idx ON image(directory_id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_directory_stem_idx ON image(directory_id, stem COLLATE NOCASE)");
_session.execute("CREATE INDEX IF NOT EXISTS image_id_idx ON image(id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_path_idx ON image(absolute_file_path)");
_session.execute("CREATE INDEX IF NOT EXISTS image_stem_idx ON image(stem)");
_session.execute("CREATE INDEX IF NOT EXISTS image_release_idx ON image(release_id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_stem_idx ON image(stem COLLATE NOCASE)");
_session.execute("CREATE INDEX IF NOT EXISTS label_name_idx ON label(name)");
+3
View File
@@ -157,6 +157,9 @@ namespace lms::db
if (params.directory.isValid())
query.where("t.directory_id = ?").bind(params.directory);
if (params.hasEmbeddedImage.has_value())
query.where("t.has_cover = ?").bind(params.hasEmbeddedImage.value());
switch (params.sortMethod)
{
case TrackSortMethod::None: