Simplified artwork handling: create a brand new artwork when an image changed. Simplifies subsonic element retrievals
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include "database/objects/Artwork.hpp"
|
||||
|
||||
#include <Wt/Dbo/Impl.h>
|
||||
#include <Wt/Dbo/WtSqlTraits.h>
|
||||
|
||||
#include "database/Session.hpp"
|
||||
#include "database/objects/Image.hpp"
|
||||
@@ -92,18 +91,6 @@ namespace lms::db
|
||||
return res;
|
||||
}
|
||||
|
||||
Wt::WDateTime Artwork::getLastWrittenTime() const
|
||||
{
|
||||
auto query{ session()->query<Wt::WDateTime>("SELECT MAX(COALESCE(image.file_last_write, track.file_last_write)) AS last_written_datetime FROM artwork") };
|
||||
query.leftJoin("image ON artwork.image_id = image.id");
|
||||
query.leftJoin("track_embedded_image ON artwork.track_embedded_image_id = track_embedded_image.id");
|
||||
query.leftJoin("track_embedded_image_link ON track_embedded_image.id = track_embedded_image_link.track_embedded_image_id");
|
||||
query.leftJoin("track ON track.id = track_embedded_image_link.track_id");
|
||||
query.where("artwork.id = ?").bind(getId());
|
||||
|
||||
return utils::fetchQuerySingleResult(query);
|
||||
}
|
||||
|
||||
std::filesystem::path Artwork::getAbsoluteFilePath() const
|
||||
{
|
||||
auto query{ session()->query<std::filesystem::path>("SELECT COALESCE(image.absolute_file_path, track.absolute_file_path) AS absolute_file_path FROM artwork") };
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <variant>
|
||||
|
||||
#include <Wt/Dbo/Field.h>
|
||||
#include <Wt/WDateTime.h>
|
||||
|
||||
#include "database/Object.hpp"
|
||||
#include "database/objects/ArtworkId.hpp"
|
||||
@@ -50,7 +49,6 @@ namespace lms::db
|
||||
// getters
|
||||
using UnderlyingId = std::variant<std::monostate, TrackEmbeddedImageId, ImageId>;
|
||||
UnderlyingId getUnderlyingId() const;
|
||||
Wt::WDateTime getLastWrittenTime() const;
|
||||
std::filesystem::path getAbsoluteFilePath() const;
|
||||
ObjectPtr<Image> getImage() const;
|
||||
ImageId getImageId() const;
|
||||
@@ -68,7 +66,6 @@ namespace lms::db
|
||||
Artwork(ObjectPtr<Image> image);
|
||||
static pointer create(Session& session, ObjectPtr<TrackEmbeddedImage> trackEmbeddedImage);
|
||||
static pointer create(Session& session, ObjectPtr<Image> image);
|
||||
|
||||
Wt::Dbo::ptr<TrackEmbeddedImage> _trackEmbeddedImage;
|
||||
Wt::Dbo::ptr<Image> _image;
|
||||
};
|
||||
|
||||
@@ -36,24 +36,15 @@ namespace lms::db::tests
|
||||
}
|
||||
|
||||
ScopedImage image{ session, "/MyImage" };
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
image.get().modify()->setAbsoluteFilePath("/tmp/foo");
|
||||
}
|
||||
ScopedArtwork artwork{ session, image.lockAndGet() };
|
||||
|
||||
const Wt::WDateTime dateTime{ Wt::WDate{ 2025, 1, 1 } };
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
EXPECT_EQ(Artwork::getCount(session), 1);
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
image.get().modify()->setLastWriteTime(dateTime);
|
||||
image.get().modify()->setAbsoluteFilePath("/tmp/foo");
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
EXPECT_EQ(artwork.get()->getLastWrittenTime(), dateTime);
|
||||
EXPECT_EQ(artwork.get()->getAbsoluteFilePath(), "/tmp/foo");
|
||||
}
|
||||
}
|
||||
@@ -67,20 +58,15 @@ namespace lms::db::tests
|
||||
|
||||
ScopedTrackEmbeddedImage image{ session };
|
||||
ScopedTrack track{ session };
|
||||
ScopedArtwork artwork{ session, image.lockAndGet() };
|
||||
|
||||
const Wt::WDateTime dateTime{ Wt::WDate{ 2025, 1, 1 } };
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
session.create<db::TrackEmbeddedImageLink>(track.get(), image.get());
|
||||
track.get().modify()->setLastWriteTime(dateTime);
|
||||
track.get().modify()->setAbsoluteFilePath("/tmp/foo");
|
||||
}
|
||||
ScopedArtwork artwork{ session, image.lockAndGet() };
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
EXPECT_EQ(artwork.get()->getLastWrittenTime(), dateTime);
|
||||
EXPECT_EQ(artwork.get()->getAbsoluteFilePath(), "/tmp/foo");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user