Make recetnly played/most played info update

This commit is contained in:
emeric
2018-06-08 16:01:03 +02:00
parent 1e68ccce2a
commit 49f92ba0f9
13 changed files with 134 additions and 40 deletions
+26
View File
@@ -44,6 +44,19 @@ TrackStats::getMostPlayedArtists(Wt::Dbo::Session& session, User::pointer user,
return std::vector<Artist::pointer>(res.begin(), res.end());
}
std::vector<Artist::pointer>
TrackStats::getLastPlayedArtists(Wt::Dbo::Session& session, User::pointer user, int limit)
{
Wt::Dbo::collection<Artist::pointer> res = session.query<Artist::pointer>
("SELECT a FROM artist a INNER JOIN track t ON a.id = t.artist_id INNER JOIN track_stats t_s ON t.id = t_s.track_id")
.where("t_s.user_id = ?").bind(user.id())
.groupBy("a.id")
.orderBy("t_s.last_played DESC")
.limit(limit);
return std::vector<Artist::pointer>(res.begin(), res.end());
}
std::vector<Release::pointer>
TrackStats::getMostPlayedReleases(Wt::Dbo::Session& session, User::pointer user, int limit)
{
@@ -57,6 +70,19 @@ TrackStats::getMostPlayedReleases(Wt::Dbo::Session& session, User::pointer user,
return std::vector<Release::pointer>(res.begin(), res.end());
}
std::vector<Release::pointer>
TrackStats::getLastPlayedReleases(Wt::Dbo::Session& session, User::pointer user, int limit)
{
Wt::Dbo::collection<Release::pointer> res = session.query<Release::pointer>
("SELECT r FROM release r INNER JOIN track t ON r.id = t.release_id INNER JOIN track_stats t_s ON t.id = t_s.track_id")
.where("t_s.user_id = ?").bind(user.id())
.groupBy("r.id")
.orderBy("t_s.last_played DESC")
.limit(limit);
return std::vector<Release::pointer>(res.begin(), res.end());
}
TrackStats::pointer
TrackStats::get(Wt::Dbo::Session& session, Track::pointer track, User::pointer user)
{
+7
View File
@@ -20,6 +20,7 @@
#pragma once
#include <Wt/Dbo/Dbo.h>
#include <Wt/WDateTime.h>
#include <string>
@@ -41,17 +42,22 @@ class TrackStats
TrackStats(Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<User> user);
static std::vector<Wt::Dbo::ptr<Artist>> getMostPlayedArtists(Wt::Dbo::Session& session, Wt::Dbo::ptr<User>, int limit = 1);
static std::vector<Wt::Dbo::ptr<Artist>> getLastPlayedArtists(Wt::Dbo::Session& session, Wt::Dbo::ptr<User>, int limit = 1);
static std::vector<Wt::Dbo::ptr<Release>> getMostPlayedReleases(Wt::Dbo::Session& session, Wt::Dbo::ptr<User>, int limit = 1);
static std::vector<Wt::Dbo::ptr<Release>> getLastPlayedReleases(Wt::Dbo::Session& session, Wt::Dbo::ptr<User>, int limit = 1);
// Get utility (will create if does not exist)
static pointer get(Wt::Dbo::Session& session, Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<User> user);
void incPlayCount() { _playCount++; }
void setLastPlayed(Wt::WDateTime lastPlayed) { _lastPlayed = lastPlayed; }
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _playCount, "play_count");
Wt::Dbo::field(a, _lastPlayed, "last_played");
Wt::Dbo::belongsTo(a, _track, "track", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _user, "user", Wt::Dbo::OnDeleteCascade);
}
@@ -59,6 +65,7 @@ class TrackStats
private:
int _playCount = 0;
Wt::WDateTime _lastPlayed;
Wt::Dbo::ptr<Track> _track;
Wt::Dbo::ptr<User> _user;
};