Getting a cover for a track will more efficiently fallback to album

This commit is contained in:
emeric
2020-11-06 15:18:20 +01:00
parent 7cd5076b93
commit 3e53d6ace1
8 changed files with 220 additions and 90 deletions
+17 -3
View File
@@ -232,15 +232,15 @@ Release::getLastWritten(Session& session,
}
std::vector<Release::pointer>
Release::getByYear(Session& session, int yearFrom, int yearTo, std::optional<std::size_t> offset, std::optional<std::size_t> limit)
Release::getByYear(Session& session, int yearFrom, int yearTo, std::optional<Range> range)
{
Wt::Dbo::collection<Release::pointer> res = session.getDboSession().query<Release::pointer>
("SELECT DISTINCT r from release r INNER JOIN track t ON r.id = t.release_id")
.where("t.year >= ?").bind(yearFrom)
.where("t.year <= ?").bind(yearTo)
.orderBy("t.year, r.name COLLATE NOCASE")
.offset(offset ? static_cast<int>(*offset) : -1)
.limit(limit ? static_cast<int>(*limit) : -1);
.offset(range ? static_cast<int>(range->offset) : -1)
.limit(range ? static_cast<int>(range->limit) : -1);
return std::vector<pointer>(res.begin(), res.end());
}
@@ -532,6 +532,20 @@ Release::getTracksCount() const
return _tracks.size();
}
Wt::Dbo::ptr<Track>
Release::getFirstTrack() const
{
assert(self());
assert(self()->id() != Wt::Dbo::dbo_traits<Artist>::invalidId());
assert(session());
return session()->query<Track::pointer>("SELECT t from track t")
.join("release r ON t.release_id = r.id")
.where("r.id = ?").bind(self()->id())
.orderBy("t.disc_number,t.track_number")
.limit(1);
}
std::chrono::milliseconds
Release::getDuration() const
{
@@ -58,7 +58,7 @@ class Release : public Wt::Dbo::Dbo<Release>
static std::vector<pointer> getAllRandom(Session& session, const std::set<IdType>& clusters, std::optional<std::size_t> size = {});
static std::vector<IdType> getAllIdsRandom(Session& session, const std::set<IdType>& clusters, std::optional<std::size_t> size = {});
static std::vector<pointer> getLastWritten(Session& session, std::optional<Wt::WDateTime> after, const std::set<IdType>& clusters, std::optional<Range> range, bool& moreResults);
static std::vector<pointer> getByYear(Session& session, int yearFrom, int yearTo, std::optional<std::size_t> offset = {}, std::optional<std::size_t> size = {});
static std::vector<pointer> getByYear(Session& session, int yearFrom, int yearTo, std::optional<Range> range = std::nullopt);
static std::vector<pointer> getStarred(Session& session, Wt::Dbo::ptr<User> user, const std::set<IdType>& clusters, std::optional<Range> range, bool& moreResults);
static std::vector<pointer> getByClusters(Session& session, const std::set<IdType>& clusters);
@@ -71,6 +71,7 @@ class Release : public Wt::Dbo::Dbo<Release>
std::vector<Wt::Dbo::ptr<Track>> getTracks(const std::set<IdType>& clusters = std::set<IdType>()) const;
std::size_t getTracksCount() const;
Wt::Dbo::ptr<Track> getFirstTrack() const;
// Get the cluster of the tracks that belong to this release
// Each clusters are grouped by cluster type, sorted by the number of occurence (max to min)