listenbrainz: added a listens synchronizer. fixes #142

This commit is contained in:
emeric
2021-04-30 17:41:03 +02:00
parent 8c5aee2e62
commit a6398738bb
33 changed files with 1359 additions and 363 deletions
+15 -2
View File
@@ -30,6 +30,7 @@
#include "utils/Logger.hpp"
#include "SqlQuery.hpp"
#include "StringViewTraits.hpp"
namespace Database {
@@ -151,12 +152,12 @@ Track::getById(Session& session, IdType id)
}
Track::pointer
Track::getByMBID(Session& session, const UUID& mbid)
Track::getByRecordingMBID(Session& session, const UUID& mbid)
{
session.checkSharedLocked();
return session.getDboSession().find<Track>()
.where("mbid = ?").bind(std::string {mbid.getAsString()});
.where("recording_mbid = ?").bind(std::string {mbid.getAsString()});
}
Track::pointer
@@ -354,6 +355,18 @@ Track::getByFilter(Session& session,
return res;
}
std::vector<Track::pointer>
Track::getByNameAndReleaseName(Session& session, std::string_view trackName, std::string_view releaseName)
{
session.checkSharedLocked();
Wt::Dbo::collection<pointer> collection = session.getDboSession().query<Track::pointer>("SELECT t from track t")
.join("release r ON t.release_id = r.id")
.where("t.name = ?").bind(trackName)
.where("r.name = ?").bind(releaseName);
return std::vector<pointer>(collection.begin(), collection.end());
}
std::vector<Track::pointer>
Track::getSimilarTracks(Session& session,
const std::unordered_set<IdType>& tracks,
+12
View File
@@ -148,6 +148,18 @@ TrackList::getEntries(std::optional<std::size_t> offset, std::optional<std::size
return std::vector<Wt::Dbo::ptr<TrackListEntry>>(entries.begin(), entries.end());
}
Wt::Dbo::ptr<TrackListEntry>
TrackList::getEntryByTrackAndDateTime(Wt::Dbo::ptr<Track> track, const Wt::WDateTime& dateTime) const
{
assert(session());
assert(IdIsValid(self()->id()));
return session()->find<TrackListEntry>()
.where("tracklist_id = ?").bind(self().id())
.where("track_id = ?").bind(track.id())
.where("date_time = ?").bind(Wt::WDateTime::fromTime_t(dateTime.toTime_t()));
}
static
Wt::Dbo::Query<Artist::pointer>
createArtistsQuery(Wt::Dbo::Session& session, const std::string& queryStr, IdType tracklistId, const std::set<IdType>& clusterIds, std::optional<TrackArtistLinkType> linkType)
+9
View File
@@ -84,6 +84,15 @@ User::getAll(Session& session)
return std::vector<pointer>(res.begin(), res.end());
}
std::vector<IdType>
User::getAllIds(Session& session)
{
session.checkSharedLocked();
Wt::Dbo::collection<IdType> res = session.getDboSession().query<IdType>("SELECT id FROM user");
return std::vector<IdType>(res.begin(), res.end());
}
User::pointer
User::getDemo(Session& session)
{
+16 -14
View File
@@ -23,6 +23,7 @@
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_set>
#include <vector>
@@ -61,7 +62,7 @@ class Track : public Wt::Dbo::Dbo<Track>
static std::size_t getCount(Session& session);
static pointer getByPath(Session& session, const std::filesystem::path& p);
static pointer getById(Session& session, IdType id);
static pointer getByMBID(Session& session, const UUID& MBID);
static pointer getByRecordingMBID(Session& session, const UUID& MBID);
static std::vector<pointer> getSimilarTracks(Session& session,
const std::unordered_set<IdType>& trackIds,
std::optional<std::size_t> offset = {},
@@ -73,6 +74,7 @@ class Track : public Wt::Dbo::Dbo<Track>
const std::vector<std::string>& keywords, // if non empty, name must match all of these keywords
std::optional<Range> range,
bool& moreExpected);
static std::vector<pointer> getByNameAndReleaseName(Session& session, std::string_view trackName, std::string_view releaseName);
static std::vector<pointer> getAll(Session& session, std::optional<std::size_t> limit = std::nullopt);
static std::vector<pointer> getAllRandom(Session& session, const std::set<IdType>& clusters, std::optional<std::size_t> limit = std::nullopt);
@@ -188,28 +190,28 @@ class Track : public Wt::Dbo::Dbo<Track>
static const std::size_t _maxCopyrightLength = 128;
static const std::size_t _maxCopyrightURLLength = 128;
int _scanVersion {};
int _trackNumber {};
int _discNumber {};
std::string _discSubtitle;
int _totalTrack {};
int _totalDisc {};
int _scanVersion {};
int _trackNumber {};
int _discNumber {};
std::string _discSubtitle;
int _totalTrack {};
int _totalDisc {};
std::string _name;
std::string _artistName;
std::string _releaseName;
std::chrono::duration<int, std::milli> _duration;
int _year {};
int _originalYear {};
std::chrono::duration<int, std::milli> _duration {};
int _year {};
int _originalYear {};
std::string _filePath;
Wt::WDateTime _fileLastWrite;
Wt::WDateTime _fileAdded;
Wt::WDateTime _fileLastWrite;
Wt::WDateTime _fileAdded;
bool _hasCover {};
std::string _trackMBID;
std::string _recordingMBID;
std::string _copyright;
std::string _copyrightURL;
std::optional<float> _trackReplayGain;
std::optional<float> _releaseReplayGain;
std::optional<float> _trackReplayGain;
std::optional<float> _releaseReplayGain;
Wt::Dbo::ptr<Release> _release;
Wt::Dbo::collection<Wt::Dbo::ptr<TrackArtistLink>> _trackArtistLinks;
@@ -84,6 +84,9 @@ class TrackList : public Wt::Dbo::Dbo<TrackList>
std::size_t getCount() const;
Wt::Dbo::ptr<TrackListEntry> getEntry(std::size_t pos) const;
std::vector<Wt::Dbo::ptr<TrackListEntry>> getEntries(std::optional<std::size_t> offset = {}, std::optional<std::size_t> size = {}) const;
Wt::Dbo::ptr<TrackListEntry> getEntryByTrackAndDateTime(Wt::Dbo::ptr<Track> track, const Wt::WDateTime& dateTime) const;
// Get track bya
std::vector<Wt::Dbo::ptr<Artist>> getArtistsReverse(const std::set<IdType>& clusterIds, std::optional<TrackArtistLinkType> linkType, std::optional<Range> range, bool& moreResults) const;
std::vector<Wt::Dbo::ptr<Release>> getReleasesReverse(const std::set<IdType>& clusterIds, std::optional<Range> range, bool& moreResults) const;
@@ -139,6 +139,7 @@ class User : public Wt::Dbo::Dbo<User>
static pointer getById(Session& session, IdType id);
static pointer getByLoginName(Session& session, std::string_view loginName);
static std::vector<pointer> getAll(Session& session);
static std::vector<IdType> getAllIds(Session& session);
static pointer getDemo(Session& session);
static std::size_t getCount(Session& session);