Finished clean on recommendation engines

This commit is contained in:
emeric
2021-09-30 19:02:49 +02:00
parent 4e9cf0d77f
commit 6baf0d313d
29 changed files with 648 additions and 634 deletions
+7
View File
@@ -66,6 +66,13 @@ Artist::getById(Session& session, ArtistId id)
return session.getDboSession().find<Artist>().where("id = ?").bind(id).resultValue();
}
bool
Artist::exists(Session& session, ArtistId id)
{
session.checkSharedLocked();
return session.getDboSession().query<int>("SELECT 1 FROM artist").where("id = ?").bind(id).resultValue() == 1;
}
Artist::pointer
Artist::create(Session& session, const std::string& name, const std::optional<UUID>& MBID)
{
+7
View File
@@ -114,6 +114,13 @@ Release::getById(Session& session, ReleaseId id)
.resultValue();
}
bool
Release::exists(Session& session, ReleaseId id)
{
session.checkSharedLocked();
return session.getDboSession().query<int>("SELECT 1 FROM release").where("id = ?").bind(id).resultValue() == 1;
}
Release::pointer
Release::create(Session& session, const std::string& name, const std::optional<UUID>& MBID)
{
+8
View File
@@ -156,6 +156,14 @@ Track::getById(Session& session, TrackId id)
.resultValue();
}
bool
Track::exists(Session& session, TrackId id)
{
session.checkSharedLocked();
return session.getDboSession().query<int>("SELECT 1 from track").where("id = ?").bind(id).resultValue() == 1;
}
std::vector<Track::pointer>
Track::getByRecordingMBID(Session& session, const UUID& mbid)
{
@@ -58,8 +58,9 @@ class Artist : public Object<Artist, ArtistId>
// Accessors
static pointer getByMBID(Session& session, const UUID& MBID);
static pointer getById(Session& session, ArtistId id);
static bool exists(Session& session, ArtistId id);
static std::vector<pointer> getByName(Session& session, const std::string& name); // exact match on name field
static std::vector<pointer> getByClusters(Session& session,
static std::vector<pointer> getByClusters(Session& session,
const std::vector<ClusterId>& clusters, // at least one track that belongs to these clusters
SortMethod sortMethod
);
@@ -50,6 +50,7 @@ class Release : public Object<Release, ReleaseId>
static pointer getByMBID(Session& session, const UUID& MBID);
static std::vector<pointer> getByName(Session& session, const std::string& name);
static pointer getById(Session& session, ReleaseId id);
static bool exists(Session& session, ReleaseId id);
static std::vector<pointer> getAllOrphans(Session& session); // no track related
static std::vector<pointer> getAll(Session& session, std::optional<Range> range = std::nullopt);
static std::vector<ReleaseId> getAllIds(Session& session);
+4 -3
View File
@@ -56,9 +56,10 @@ class Track : public Object<Track, TrackId>
Track(const std::filesystem::path& p);
// Find utility functions
static std::size_t getCount(Session& session);
static pointer getByPath(Session& session, const std::filesystem::path& p);
static pointer getById(Session& session, TrackId id);
static std::size_t getCount(Session& session);
static pointer getByPath(Session& session, const std::filesystem::path& p);
static pointer getById(Session& session, TrackId id);
static bool exists(Session& session, TrackId id);
static std::vector<pointer> getByRecordingMBID(Session& session, const UUID& MBID);
static std::vector<pointer> getSimilarTracks(Session& session,
const std::vector<TrackId>& trackIds,
+9
View File
@@ -23,6 +23,13 @@ using namespace Database;
TEST_F(DatabaseFixture, SingleArtist)
{
{
auto transaction {session.createSharedTransaction()};
EXPECT_FALSE(Artist::exists(session, 35));
EXPECT_FALSE(Artist::exists(session, 0));
EXPECT_FALSE(Artist::exists(session, 1));
}
ScopedArtist artist {session, "MyArtist"};
{
@@ -31,6 +38,8 @@ TEST_F(DatabaseFixture, SingleArtist)
EXPECT_TRUE(artist.get());
EXPECT_FALSE(!artist.get());
EXPECT_EQ(artist.get()->getId(), artist.getId());
EXPECT_TRUE(Artist::exists(session, artist.getId()));
}
{
+9
View File
@@ -23,11 +23,20 @@ using namespace Database;
TEST_F(DatabaseFixture, SingleRelease)
{
{
auto transaction {session.createSharedTransaction()};
EXPECT_FALSE(Release::exists(session, 0));
EXPECT_FALSE(Release::exists(session, 1));
}
ScopedRelease release {session, "MyRelease"};
{
auto transaction {session.createSharedTransaction()};
EXPECT_TRUE(Release::exists(session, release.getId()));
auto releases {Release::getAllOrphans(session)};
ASSERT_EQ(releases.size(), 1);
EXPECT_EQ(releases.front()->getId(), release.getId());
+5
View File
@@ -28,6 +28,7 @@ TEST_F(DatabaseFixture, SingleTrack)
{
auto transaction {session.createSharedTransaction()};
EXPECT_EQ(Track::getCount(session), 0);
EXPECT_FALSE(Track::exists(session, 0));
}
ScopedTrack track {session, "MyTrackFile"};
@@ -37,6 +38,10 @@ TEST_F(DatabaseFixture, SingleTrack)
EXPECT_EQ(Track::getAll(session).size(), 1);
EXPECT_EQ(Track::getCount(session), 1);
EXPECT_TRUE(Track::exists(session, track.getId()));
auto myTrack {Track::getById(session, track.getId())};
ASSERT_TRUE(myTrack);
EXPECT_EQ(myTrack->getId(), track.getId());
}
}