Update CategoryTrackListQuery to also include duration. Untested, checking this in to test on a computer that has easier access to local music.

This commit is contained in:
casey langen 2021-01-25 22:06:44 -08:00
parent db9f12551a
commit 960c9a55f4
3 changed files with 24 additions and 5 deletions

View File

@ -97,6 +97,7 @@ CategoryTrackListQuery::CategoryTrackListQuery(
this->library = library;
this->result = std::make_shared<TrackList>(library);
this->headers = std::make_shared<std::set<size_t>>();
this->durations = std::make_shared<std::map<size_t, size_t>>();
this->hash = category::Hash(predicates);
this->sortType = sortType;
@ -128,6 +129,10 @@ size_t CategoryTrackListQuery::GetQueryHash() noexcept {
return this->hash;
}
CategoryTrackListQuery::Durations CategoryTrackListQuery::GetDurations() noexcept {
return this->durations;
}
void CategoryTrackListQuery::PlaylistQuery(musik::core::db::Connection &db) {
/* playlists are a special case. we already have a query for this, so
delegate to that. */
@ -171,18 +176,33 @@ void CategoryTrackListQuery::ProcessResult(musik::core::db::Statement& trackQuer
std::string lastAlbum;
size_t index = 0;
size_t lastHeaderIndex = 0;
size_t runningDuration = 0;
while (trackQuery.Step() == Row) {
const int64_t id = trackQuery.ColumnInt64(0);
std::string album = trackQuery.ColumnText(1);
std::string album = trackQuery.ColumnText(2);
runningDuration += trackQuery.ColumnInt32(1);
if (this->parseHeaders && album != lastAlbum) {
headers->insert(index);
if (!headers->empty()) {
(*durations)[lastHeaderIndex] = runningDuration;
lastHeaderIndex = index;
runningDuration = 0;
}
lastAlbum = album;
}
result->Add(id);
++index;
}
if (this->parseHeaders && !headers->empty()) {
(*durations)[lastHeaderIndex] = runningDuration;
}
}
bool CategoryTrackListQuery::OnRun(Connection& db) {

View File

@ -81,10 +81,8 @@ namespace musik { namespace core { namespace library { namespace query {
/* TrackListQueryBase */
Result GetResult() noexcept override;
Headers GetHeaders() noexcept override;
Durations GetDurations() noexcept override;
size_t GetQueryHash() noexcept override;
Durations GetDurations() noexcept override {
return std::make_shared<std::map<size_t, size_t>>();
}
/* ISerializableQuery */
std::string SerializeQuery() override;
@ -116,6 +114,7 @@ namespace musik { namespace core { namespace library { namespace query {
/* serialized result fields */
Result result;
Headers headers;
Durations durations;
/* serialized query fields */
std::string filter;

View File

@ -175,7 +175,7 @@ namespace musik { namespace core { namespace library { namespace query {
/* note: al.name needs to be the second column selected to ensure proper grouping by
album in the UI layer! */
static const std::string CATEGORY_TRACKLIST_QUERY =
"SELECT DISTINCT tracks.id, al.name, tracks.date_added, tracks.date_updated, tracks.last_played, tracks.play_count, tracks.rating "
"SELECT DISTINCT tracks.id, tracks.duration, al.name "
"FROM tracks, albums al, artists ar, genres gn "
"{{extended_predicates}} "
"WHERE "