Skip to content

Commit

Permalink
Merge branch 'develop' for release v3.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
epoupon committed Oct 20, 2022
2 parents 1f5cb68 + a3884c2 commit 95462cb
Show file tree
Hide file tree
Showing 44 changed files with 1,504 additions and 359 deletions.
7 changes: 3 additions & 4 deletions docroot/js/mediaplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ LMS.mediaplayer = function () {
_initAudioCtx();
};

document.addEventListener("touchstart", _unlock);
document.addEventListener("touchend", _unlock);
document.addEventListener("click", _unlock);

let _initAudioCtx = function() {
if (_audioIsInit) {
_audioCtx.resume(); // not sure of this
Expand Down Expand Up @@ -321,6 +317,9 @@ LMS.mediaplayer = function () {
event.preventDefault();
});

document.addEventListener("touchstart", _unlock);
document.addEventListener("touchend", _unlock);
document.addEventListener("click", _unlock);
}

let _removeAudioSources = function() {
Expand Down
4 changes: 4 additions & 0 deletions src/libs/services/database/impl/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ Session::prepareTables()
_session.execute("CREATE INDEX IF NOT EXISTS track_bookmark_user_track_idx ON track_bookmark(user_id,track_id)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_scrobbler_idx ON listen(scrobbler)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_user_scrobbler_idx ON listen(user_id,scrobbler)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_user_track_scrobbler_date_time_idx ON listen(user_id,track_id,scrobbler,date_time)");
_session.execute("CREATE INDEX IF NOT EXISTS starred_artist_user_scrobbler_idx ON starred_artist(user_id,scrobbler)");
_session.execute("CREATE INDEX IF NOT EXISTS starred_artist_artist_user_scrobbler_idx ON starred_artist(artist_id,user_id,scrobbler)");
_session.execute("CREATE INDEX IF NOT EXISTS starred_release_user_scrobbler_idx ON starred_release(user_id,scrobbler)");
_session.execute("CREATE INDEX IF NOT EXISTS starred_release_release_user_scrobbler_idx ON starred_release(release_id,user_id,scrobbler)");
_session.execute("CREATE INDEX IF NOT EXISTS starred_track_user_scrobbler_idx ON starred_track(user_id,scrobbler)");
_session.execute("CREATE INDEX IF NOT EXISTS starred_track_track_user_scrobbler_idx ON starred_track(track_id,user_id,scrobbler)");
}

// Initial settings tables
Expand Down
63 changes: 47 additions & 16 deletions src/libs/services/database/impl/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ createQuery(Session& session, const Track::FindParameters& params)

auto query {session.getDboSession().query<TrackId>(params.distinct ? "SELECT DISTINCT t.id FROM track t" : "SELECT t.id FROM track t")};

assert(params.keywords.empty() || params.name.empty());
for (std::string_view keyword : params.keywords)
query.where("t.name LIKE ? ESCAPE '" ESCAPE_CHAR_STR "'").bind("%" + Utils::escapeLikeKeyword(keyword) + "%");

if (!params.name.empty())
query.where("t.name = ?").bind(params.name);

if (params.writtenAfter.isValid())
query.where("t.file_last_write > ?").bind(params.writtenAfter);

Expand Down Expand Up @@ -80,11 +84,15 @@ createQuery(Session& session, const Track::FindParameters& params)
query.where(oss.str());
}

if (params.artist.isValid())
if (params.artist.isValid() || !params.artistName.empty())
{
query.join("artist a ON a.id = t_a_l.artist_id")
.join("track_artist_link t_a_l ON t_a_l.track_id = t.id")
.where("a.id = ?").bind(params.artist);
.join("track_artist_link t_a_l ON t_a_l.track_id = t.id");

if (params.artist.isValid())
query.where("a.id = ?").bind(params.artist);
if (!params.artistName.empty())
query.where("a.name = ?").bind(params.artistName);

if (!params.trackArtistLinkTypes.empty())
{
Expand All @@ -109,6 +117,11 @@ createQuery(Session& session, const Track::FindParameters& params)
query.where("t.release_id IS NULL");
else if (params.release.isValid())
query.where("t.release_id = ?").bind(params.release);
else if (!params.releaseName.empty())
{
query.join("release r ON t.release_id = r.id");
query.where("r.name = ?").bind(params.releaseName);
}

if (params.trackList.isValid())
{
Expand All @@ -117,6 +130,9 @@ createQuery(Session& session, const Track::FindParameters& params)
query.where("t_l.id = ?").bind(params.trackList);
}

if (params.trackNumber)
query.where("t.track_number = ?").bind(*params.trackNumber);

switch (params.sortMethod)
{
case TrackSortMethod::None:
Expand Down Expand Up @@ -282,19 +298,6 @@ Track::find(Session& session, const FindParameters& parameters)
return Utils::execQuery(query, parameters.range);
}

RangeResults<TrackId>
Track::findByNameAndReleaseName(Session& session, std::string_view trackName, std::string_view releaseName)
{
session.checkSharedLocked();

auto query {session.getDboSession().query<TrackId>("SELECT t.id from track t")
.join("release r ON t.release_id = r.id")
.where("t.name = ?").bind(trackName)
.where("r.name = ?").bind(releaseName)};

return Utils::execQuery(query, Range {});
}

RangeResults<TrackId>
Track::findSimilarTracks(Session& session, const std::vector<TrackId>& tracks, Range range)
{
Expand Down Expand Up @@ -517,5 +520,33 @@ Track::getClusterGroups(const std::vector<ClusterType::pointer>& clusterTypes, s
return res;
}

namespace Debug
{
std::ostream&
operator<<(std::ostream& os, const TrackInfo& trackInfo)
{
auto transaction {trackInfo.session.createSharedTransaction()};

const Track::pointer track {Track::find(trackInfo.session, trackInfo.trackId)};
if (track)
{
os << track->getName();

if (const Release::pointer release {track->getRelease()})
os << " [" << release->getName() << "]";
for (auto artist : track->getArtists({TrackArtistLinkType::Artist}))
os << " - " << artist->getName();
for (auto cluster : track->getClusters())
os << " {" + cluster->getType()->getName() << "-" << cluster->getName() << "}";
}
else
{
os << "*unknown*";
}

return os;
}
}

} // namespace Database

31 changes: 25 additions & 6 deletions src/libs/services/database/include/services/database/Track.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

#include <chrono>
#include <filesystem>
#include <iostream>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_set>
#include <utility>
#include <vector>

#include <Wt/WDateTime.h>
Expand Down Expand Up @@ -59,30 +61,38 @@ class Track : public Object<Track, TrackId>
public:
struct FindParameters
{
std::vector<ClusterId> clusters; // if non empty, tracks that belong to these clusters
std::vector<std::string_view> keywords; // if non empty, name must match all of these keywords
std::vector<ClusterId> clusters; // if non empty, tracks that belong to these clusters
std::vector<std::string_view> keywords; // if non empty, name must match all of these keywords
std::string name; // if non empty, must match this name
TrackSortMethod sortMethod {TrackSortMethod::None};
Range range;
Wt::WDateTime writtenAfter;
UserId starringUser; // only tracks starred by this user
std::optional<Scrobbler> scrobbler; // and for this scrobbler
ArtistId artist; // only tracks that involve this user
ArtistId artist; // only tracks that involve this artist
std::string artistName; // only tracks that involve this artist name
EnumSet<TrackArtistLinkType> trackArtistLinkTypes; // and for these link types
bool nonRelease {}; // only tracks that do not belong to a release
ReleaseId release; // matching this release
std::string releaseName; // matching this release name
TrackListId trackList; // matching this trackList
std::optional<int> trackNumber; // matching this track number
bool distinct {true};

FindParameters& setClusters(const std::vector<ClusterId>& _clusters) { clusters = _clusters; return *this; }
FindParameters& setKeywords(const std::vector<std::string_view>& _keywords) { keywords = _keywords; return *this; }
FindParameters& setName(std::string_view _name) { name = _name; return *this; }
FindParameters& setSortMethod(TrackSortMethod _method) { sortMethod = _method; return *this; }
FindParameters& setRange(Range _range) { range = _range; return *this; }
FindParameters& setWrittenAfter(const Wt::WDateTime& _after) { writtenAfter = _after; return *this; }
FindParameters& setStarringUser(UserId _user, Scrobbler _scrobbler) { starringUser = _user; scrobbler = _scrobbler; return *this; }
FindParameters& setArtist(ArtistId _artist, EnumSet<TrackArtistLinkType> _trackArtistLinkTypes = {}) { artist = _artist; trackArtistLinkTypes = _trackArtistLinkTypes; return *this; }
FindParameters& setArtistName(std::string_view _artistName, EnumSet<TrackArtistLinkType> _trackArtistLinkTypes = {}) { artistName = _artistName; trackArtistLinkTypes = _trackArtistLinkTypes; return *this; }
FindParameters& setNonRelease(bool _nonRelease) { nonRelease = _nonRelease; return *this; }
FindParameters& setRelease(ReleaseId _release) { release = _release; return *this; }
FindParameters& setReleaseName(std::string_view _releaseName) { releaseName = _releaseName; return *this; }
FindParameters& setTrackList(TrackListId _trackList) { trackList = _trackList; return *this; }
FindParameters& setTrackNumber(int _trackNumber) { trackNumber = _trackNumber; return *this; }
FindParameters& setDistinct(bool _distinct) { distinct = _distinct; return *this; }
};

Expand All @@ -103,7 +113,6 @@ class Track : public Object<Track, TrackId>
static RangeResults<TrackId> findSimilarTracks(Session& session, const std::vector<TrackId>& trackIds, Range range);

static RangeResults<TrackId> find(Session& session, const FindParameters& parameters);
static RangeResults<TrackId> findByNameAndReleaseName(Session& session, std::string_view trackName, std::string_view releaseName);
static RangeResults<PathResult> findPaths(Session& session, Range range);
static RangeResults<TrackId> findRecordingMBIDDuplicates(Session& session, Range range);
static RangeResults<TrackId> findWithRecordingMBIDAndMissingFeatures(Session& session, Range range);
Expand Down Expand Up @@ -156,8 +165,8 @@ class Track : public Object<Track, TrackId>
std::optional<float> getReleaseReplayGain() const { return _releaseReplayGain; }

// no artistLinkTypes means get all
std::vector<ObjectPtr<Artist>> getArtists(EnumSet<TrackArtistLinkType> artistLinkTypes) const;
std::vector<ArtistId> getArtistIds(EnumSet<TrackArtistLinkType> artistLinkTypes) const;
std::vector<ObjectPtr<Artist>> getArtists(EnumSet<TrackArtistLinkType> artistLinkTypes) const; // no type means all
std::vector<ArtistId> getArtistIds(EnumSet<TrackArtistLinkType> artistLinkTypes) const; // no type means all
std::vector<ObjectPtr<TrackArtistLink>> getArtistLinks() const;
ObjectPtr<Release> getRelease() const { return _release; }
std::vector<ObjectPtr<Cluster>> getClusters() const;
Expand Down Expand Up @@ -230,6 +239,16 @@ class Track : public Object<Track, TrackId>
Wt::Dbo::collection<Wt::Dbo::ptr<Cluster>> _clusters;
};

namespace Debug
{
struct TrackInfo
{
Session& session;
TrackId trackId;
};
std::ostream& operator<<(std::ostream& os, const TrackInfo& trackInfo);
}

} // namespace database


18 changes: 18 additions & 0 deletions src/libs/services/database/test/Artist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ TEST_F(DatabaseFixture, Artist_singleTrack)
{
auto transaction {session.createUniqueTransaction()};

track.get().modify()->setName("MyTrackName");
TrackArtistLink::create(session, track.get(), artist.get(), TrackArtistLinkType::Artist);
}

Expand All @@ -89,6 +90,23 @@ TEST_F(DatabaseFixture, Artist_singleTrack)
EXPECT_TRUE(track->getArtists({TrackArtistLinkType::ReleaseArtist}).empty());
EXPECT_EQ(track->getArtists({}).size(), 1);
}

{
auto transaction {session.createUniqueTransaction()};
auto tracks {Track::find(session, Track::FindParameters{}.setName("MyTrackName").setArtistName("MyArtist"))};
ASSERT_EQ(tracks.results.size(), 1);
EXPECT_EQ(tracks.results.front(), track.getId());
}
{
auto transaction {session.createUniqueTransaction()};
auto tracks {Track::find(session, Track::FindParameters{}.setName("MyTrackName").setArtistName("MyArtistFoo"))};
EXPECT_EQ(tracks.results.size(), 0);
}
{
auto transaction {session.createUniqueTransaction()};
auto tracks {Track::find(session, Track::FindParameters{}.setName("MyTrackNameFoo").setArtistName("MyArtist"))};
EXPECT_EQ(tracks.results.size(), 0);
}
}

TEST_F(DatabaseFixture, Artist_singleTracktMultiRoles)
Expand Down
6 changes: 3 additions & 3 deletions src/libs/services/database/test/Release.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ TEST_F(DatabaseFixture, Release_singleTrack)

{
auto transaction {session.createUniqueTransaction()};
auto tracks {Track::findByNameAndReleaseName(session, "MyTrackName", "MyReleaseName")};
auto tracks {Track::find(session, Track::FindParameters{}.setName("MyTrackName").setReleaseName("MyReleaseName"))};
ASSERT_EQ(tracks.results.size(), 1);
EXPECT_EQ(tracks.results.front(), track.getId());
}
{
auto transaction {session.createUniqueTransaction()};
auto tracks {Track::findByNameAndReleaseName(session, "MyTrackName", "MyReleaseFoo")};
auto tracks {Track::find(session, Track::FindParameters{}.setName("MyTrackName").setReleaseName("MyReleaseFoo"))};
EXPECT_EQ(tracks.results.size(), 0);
}
{
auto transaction {session.createUniqueTransaction()};
auto tracks {Track::findByNameAndReleaseName(session, "MyTrackFoo", "MyReleaseName")};
auto tracks {Track::find(session, Track::FindParameters{}.setName("MyTrackFoo").setReleaseName("MyReleaseName"))};
EXPECT_EQ(tracks.results.size(), 0);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/libs/services/recommendation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ add_library(lmsrecommendation SHARED
impl/features/FeaturesEngineCache.cpp
impl/features/FeaturesEngine.cpp
impl/features/FeaturesDefs.cpp
impl/playlist-constraints/ConsecutiveArtists.cpp
impl/playlist-constraints/ConsecutiveReleases.cpp
impl/playlist-constraints/DuplicateTracks.cpp
impl/PlaylistGeneratorService.cpp
impl/RecommendationService.cpp
)

Expand Down
Loading

0 comments on commit 95462cb

Please sign in to comment.