From 9edad1314ee4fbd5c56768396cdf24406544d433 Mon Sep 17 00:00:00 2001 From: emeric Date: Sat, 2 May 2020 14:34:40 +0200 Subject: [PATCH] Use the last modified file attribute in order to display recently added items. fixes #51 --- src/libs/database/impl/Artist.cpp | 6 +++--- src/libs/database/impl/Release.cpp | 6 +++--- src/libs/database/impl/Track.cpp | 6 +++--- src/libs/database/include/database/Artist.hpp | 2 +- src/libs/database/include/database/Release.hpp | 2 +- src/libs/database/include/database/Track.hpp | 2 +- src/libs/subsonic/impl/SubsonicResource.cpp | 2 +- src/lms/ui/explore/ArtistsInfoView.cpp | 4 ++-- src/lms/ui/explore/ReleasesInfoView.cpp | 4 ++-- src/lms/ui/explore/TracksInfoView.cpp | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libs/database/impl/Artist.cpp b/src/libs/database/impl/Artist.cpp index 8f310180..cba62539 100644 --- a/src/libs/database/impl/Artist.cpp +++ b/src/libs/database/impl/Artist.cpp @@ -230,13 +230,13 @@ Artist::getByFilter(Session& session, } std::vector -Artist::getLastAdded(Session& session, Wt::WDateTime after, std::optional limit) +Artist::getLastWritten(Session& session, Wt::WDateTime after, std::optional limit) { session.checkSharedLocked(); Wt::Dbo::collection res = session.getDboSession().query("SELECT a from artist a INNER JOIN track_artist_link t_a_l ON t_a_l.artist_id = a.id INNER JOIN track t ON t.id = t_a_l.track_id") - .where("t.file_added > ?").bind(after) + .where("t.file_last_write > ?").bind(after) .groupBy("a.id") - .orderBy("t.file_added DESC") + .orderBy("t.file_last_write DESC") .limit(limit ? static_cast(*limit) : -1); return std::vector(res.begin(), res.end()); diff --git a/src/libs/database/impl/Release.cpp b/src/libs/database/impl/Release.cpp index a8535f49..d7c8491b 100644 --- a/src/libs/database/impl/Release.cpp +++ b/src/libs/database/impl/Release.cpp @@ -145,14 +145,14 @@ Release::getAllOrphans(Session& session) } std::vector -Release::getLastAdded(Session& session, const Wt::WDateTime& after, std::optional offset, std::optional limit) +Release::getLastWritten(Session& session, const Wt::WDateTime& after, std::optional offset, std::optional limit) { session.checkSharedLocked(); Wt::Dbo::collection res = session.getDboSession().query("SELECT r from release r INNER JOIN track t ON r.id = t.release_id") - .where("t.file_added > ?").bind(after) + .where("t.file_last_write > ?").bind(after) .groupBy("r.id") - .orderBy("t.file_added DESC") + .orderBy("t.file_last_write DESC") .offset(offset ? static_cast(*offset) : -1) .limit(limit ? static_cast(*limit) : -1); diff --git a/src/libs/database/impl/Track.cpp b/src/libs/database/impl/Track.cpp index f0deedab..cc286ee0 100644 --- a/src/libs/database/impl/Track.cpp +++ b/src/libs/database/impl/Track.cpp @@ -147,13 +147,13 @@ Track::getMBIDDuplicates(Session& session) } std::vector -Track::getLastAdded(Session& session, const Wt::WDateTime& after, std::optional limit) +Track::getLastWritten(Session& session, const Wt::WDateTime& after, std::optional limit) { session.checkSharedLocked(); Wt::Dbo::collection res = session.getDboSession().find() - .where("file_added > ?").bind(after) - .orderBy("file_added DESC") + .where("file_last_write > ?").bind(after) + .orderBy("file_last_write DESC") .limit(limit ? static_cast(*limit) : -1); return std::vector(res.begin(), res.end()); diff --git a/src/libs/database/include/database/Artist.hpp b/src/libs/database/include/database/Artist.hpp index f6f5df7b..f29d4637 100644 --- a/src/libs/database/include/database/Artist.hpp +++ b/src/libs/database/include/database/Artist.hpp @@ -77,7 +77,7 @@ class Artist : public Wt::Dbo::Dbo static std::vector getAll(Session& session, SortMethod sortMethod, std::optional offset = {}, std::optional size = {}); static std::vector getAllIds(Session& session); static std::vector getAllOrphans(Session& session); // No track related - static std::vector getLastAdded(Session& session, Wt::WDateTime after, std::optional size = {}); + static std::vector getLastWritten(Session& session, Wt::WDateTime after, std::optional size = {}); static std::vector getAllIdsWithClusters(Session& session, std::optional limit = {}); // Accessors diff --git a/src/libs/database/include/database/Release.hpp b/src/libs/database/include/database/Release.hpp index 29b93c58..7b61148b 100644 --- a/src/libs/database/include/database/Release.hpp +++ b/src/libs/database/include/database/Release.hpp @@ -56,7 +56,7 @@ class Release : public Wt::Dbo::Dbo static std::vector getAllIds(Session& session); static std::vector getAllOrderedByArtist(Session& session, std::optional offset = {}, std::optional size = {}); static std::vector getAllRandom(Session& session, std::optional size = {}); - static std::vector getLastAdded(Session& session, const Wt::WDateTime& after, std::optional offset = {}, std::optional size = {}); + static std::vector getLastWritten(Session& session, const Wt::WDateTime& after, std::optional offset = {}, std::optional size = {}); static std::vector getByYear(Session& session, int yearFrom, int yearTo, std::optional offset = {}, std::optional size = {}); static std::vector getByClusters(Session& session, const std::set& clusters); diff --git a/src/libs/database/include/database/Track.hpp b/src/libs/database/include/database/Track.hpp index 9dbd4083..4a83f560 100644 --- a/src/libs/database/include/database/Track.hpp +++ b/src/libs/database/include/database/Track.hpp @@ -77,7 +77,7 @@ class Track : public Wt::Dbo::Dbo static std::vector getAllIds(Session& session); static std::vector> getAllPaths(Session& session, std::optional offset = std::nullopt, std::optional size = std::nullopt); static std::vector getMBIDDuplicates(Session& session); - static std::vector getLastAdded(Session& session, const Wt::WDateTime& after, std::optional size = 1); + static std::vector getLastWritten(Session& session, const Wt::WDateTime& after, std::optional size = 1); static std::vector getAllWithMBIDAndMissingFeatures(Session& session); static std::vector getAllIdsWithFeatures(Session& session, std::optional limit = {}); static std::vector getAllIdsWithClusters(Session& session, std::optional limit = {}); diff --git a/src/libs/subsonic/impl/SubsonicResource.cpp b/src/libs/subsonic/impl/SubsonicResource.cpp index b34211a9..bab3fa94 100644 --- a/src/libs/subsonic/impl/SubsonicResource.cpp +++ b/src/libs/subsonic/impl/SubsonicResource.cpp @@ -696,7 +696,7 @@ handleGetAlbumListRequestCommon(const RequestContext& context, bool id3) else if (type == "newest") { auto after {Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-6)}; - releases = Release::getLastAdded(context.dbSession, after, offset, size); + releases = Release::getLastWritten(context.dbSession, after, offset, size); } else if (type == "alphabeticalByName") { diff --git a/src/lms/ui/explore/ArtistsInfoView.cpp b/src/lms/ui/explore/ArtistsInfoView.cpp index e9181a64..ac0dd65d 100644 --- a/src/lms/ui/explore/ArtistsInfoView.cpp +++ b/src/lms/ui/explore/ArtistsInfoView.cpp @@ -57,10 +57,10 @@ ArtistsInfo::ArtistsInfo() void ArtistsInfo::refreshRecentlyAdded() { - auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1); + auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-6); auto transaction {LmsApp->getDbSession().createSharedTransaction()}; - const std::vector artists {Artist::getLastAdded(LmsApp->getDbSession(), after, 5)}; + const std::vector artists {Artist::getLastWritten(LmsApp->getDbSession(), after, 5)}; _recentlyAddedContainer->clear(); for (const Database::Artist::pointer& artist : artists) diff --git a/src/lms/ui/explore/ReleasesInfoView.cpp b/src/lms/ui/explore/ReleasesInfoView.cpp index 0693cc32..f5690ec8 100644 --- a/src/lms/ui/explore/ReleasesInfoView.cpp +++ b/src/lms/ui/explore/ReleasesInfoView.cpp @@ -58,11 +58,11 @@ ReleasesInfo::ReleasesInfo() void ReleasesInfo::refreshRecentlyAdded() { - auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1); + auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-6); auto transaction {LmsApp->getDbSession().createSharedTransaction()}; - const auto releases {Release::getLastAdded(LmsApp->getDbSession(), after, 0, 5)}; + const auto releases {Release::getLastWritten(LmsApp->getDbSession(), after, 0, 5)}; _recentlyAddedContainer->clear(); for (const Database::Release::pointer& release : releases) diff --git a/src/lms/ui/explore/TracksInfoView.cpp b/src/lms/ui/explore/TracksInfoView.cpp index d05cc200..b4907003 100644 --- a/src/lms/ui/explore/TracksInfoView.cpp +++ b/src/lms/ui/explore/TracksInfoView.cpp @@ -74,10 +74,10 @@ TracksInfo::TracksInfo() void TracksInfo::refreshRecentlyAdded() { - const auto after {Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1)}; + const auto after {Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-6)}; auto transaction {LmsApp->getDbSession().createSharedTransaction()}; - const auto tracks {Track::getLastAdded(LmsApp->getDbSession(), after, 5)}; + const auto tracks {Track::getLastWritten(LmsApp->getDbSession(), after, 5)}; _recentlyAddedContainer->clear(); addEntries(_recentlyAddedContainer, tracks);