Send pending listens that have not been successfully sent
This commit is contained in:
@@ -155,17 +155,24 @@ namespace Database
|
||||
return session.getDboSession().find<Listen>().where("id = ?").bind(id).resultValue();
|
||||
}
|
||||
|
||||
RangeResults<Listen::pointer>
|
||||
Listen::find(Session& session, UserId userId, Scrobbler scrobbler, Range range)
|
||||
RangeResults<ListenId>
|
||||
Listen::find(Session& session, const FindParameters& parameters)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
auto query {session.getDboSession().find<Listen>()
|
||||
.where("user_id = ?").bind(userId)
|
||||
.where("scrobbler = ?").bind(scrobbler)
|
||||
.orderBy("date_time")};
|
||||
auto query {session.getDboSession().query<ListenId>("SELECT id FROM listen")
|
||||
.orderBy("date_time")};
|
||||
|
||||
return execQuery(query, range);
|
||||
if (parameters.user.isValid())
|
||||
query.where("user_id = ?").bind(parameters.user);
|
||||
|
||||
if (parameters.scrobbler)
|
||||
query.where("scrobbler = ?").bind(*parameters.scrobbler);
|
||||
|
||||
if (parameters.scrobblingState)
|
||||
query.where("scrobbling_state = ?").bind(*parameters.scrobblingState);
|
||||
|
||||
return execQuery(query, parameters.range);
|
||||
}
|
||||
|
||||
Listen::pointer
|
||||
|
||||
@@ -75,6 +75,13 @@ namespace Database::Migration
|
||||
Db& _db;
|
||||
};
|
||||
|
||||
static
|
||||
std::string
|
||||
dateTimeToDbFormat(const Wt::WDateTime& dateTime)
|
||||
{
|
||||
return dateTime.toString("yyyy'-'MM'-'dd'T'hh':'mm':'ss'.000'", false).toUTF8();
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
migrateFromV5(Session& session)
|
||||
@@ -450,7 +457,7 @@ CREATE TABLE "starred_track" (
|
||||
// Can't migrate using class mapping as mapping may evolve in the future
|
||||
|
||||
// use time_t to avoid rounding issues later
|
||||
const Wt::WDateTime now {Wt::WDateTime::fromTime_t(Wt::WDateTime::currentDateTime().toTime_t())};
|
||||
const std::string now {dateTimeToDbFormat(Wt::WDateTime::fromTime_t(Wt::WDateTime::currentDateTime().toTime_t()))};
|
||||
|
||||
std::map<IdType::ValueType, Scrobbler> userScrobblers;
|
||||
auto getScrobbler {[&](IdType::ValueType userId)
|
||||
@@ -480,7 +487,7 @@ CREATE TABLE "starred_track" (
|
||||
session.getDboSession().execute("INSERT INTO " + newTableName + " ('version', 'scrobbler', 'date_time', '" + colName + "', 'user_id') VALUES (?, ?, ?, ?, ?)")
|
||||
.bind(0)
|
||||
.bind(getScrobbler(userId))
|
||||
.bind(now.toString().toUTF8())
|
||||
.bind(now)
|
||||
.bind(entryId)
|
||||
.bind(userId);
|
||||
}
|
||||
@@ -523,7 +530,7 @@ CREATE TABLE "listen" (
|
||||
{
|
||||
session.getDboSession().execute("INSERT INTO listen ('version', 'date_time', 'scrobbler', 'scrobbling_state', 'track_id', 'user_id') VALUES (?, ?, ?, ?, ?, ?)")
|
||||
.bind(0)
|
||||
.bind(dateTime.toString().toUTF8())
|
||||
.bind(dateTimeToDbFormat(dateTime))
|
||||
.bind(scrobbler)
|
||||
.bind(ScrobblingState::Synchronized) // consider sync is done to avoid duplicate submissions
|
||||
.bind(trackId)
|
||||
|
||||
@@ -44,13 +44,16 @@ User::getCount(Session& session)
|
||||
}
|
||||
|
||||
RangeResults<UserId>
|
||||
User::find(Session& session, Range range)
|
||||
User::find(Session& session, const FindParameters& params)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
auto query {session.getDboSession().query<UserId>("SELECT id FROM user")};
|
||||
|
||||
return execQuery(query, range);
|
||||
if (params.scrobbler)
|
||||
query.where("scrobbler = ?").bind(*params.scrobbler);
|
||||
|
||||
return execQuery(query, params.range);
|
||||
}
|
||||
|
||||
User::pointer
|
||||
|
||||
Reference in New Issue
Block a user