From 3a1ffc17e50ff216009dec5a29ac445b0a947641 Mon Sep 17 00:00:00 2001 From: emeric Date: Sun, 30 Apr 2023 21:45:54 +0200 Subject: [PATCH] Do not rerender artist and release views if the path is already rendered --- src/lms/ui/explore/ArtistView.cpp | 15 ++++++++++----- src/lms/ui/explore/ReleaseView.cpp | 31 ++++++++++++++++++------------ src/lms/ui/explore/ReleaseView.hpp | 1 + 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/lms/ui/explore/ArtistView.cpp b/src/lms/ui/explore/ArtistView.cpp index bb74eba1..672ddeb6 100644 --- a/src/lms/ui/explore/ArtistView.cpp +++ b/src/lms/ui/explore/ArtistView.cpp @@ -108,11 +108,16 @@ Artist::refreshView() if (!wApp->internalPathMatches("/artist/")) return; + const auto artistId {extractArtistIdFromInternalPath()}; + + // consider everything is up to date is the same artist is being rendered + if (artistId && *artistId == _artistId) + return; + clear(); _artistId = {}; _trackContainer = nullptr; - const auto artistId {extractArtistIdFromInternalPath()}; if (!artistId) throw ArtistNotFoundException {}; @@ -177,22 +182,22 @@ Artist::refreshView() _playQueueController.processCommand(PlayQueueController::Command::PlayOrAddLast, {_artistId}); }); bindNew("download", Wt::WString::tr("Lms.Explore.download")) - ->setLink(Wt::WLink {std::make_unique(*artistId)}); + ->setLink(Wt::WLink {std::make_unique(_artistId)}); { - auto isStarred {[=] { return Service::get()->isStarred(LmsApp->getUserId(), *artistId); }}; + auto isStarred {[=] { return Service::get()->isStarred(LmsApp->getUserId(), _artistId); }}; Wt::WPushButton* starBtn {bindNew("star", Wt::WString::tr(isStarred() ? "Lms.Explore.unstar" : "Lms.Explore.star"))}; starBtn->clicked().connect([=] { if (isStarred()) { - Service::get()->unstar(LmsApp->getUserId(), *artistId); + Service::get()->unstar(LmsApp->getUserId(), _artistId); starBtn->setText(Wt::WString::tr("Lms.Explore.star")); } else { - Service::get()->star(LmsApp->getUserId(), *artistId); + Service::get()->star(LmsApp->getUserId(), _artistId); starBtn->setText(Wt::WString::tr("Lms.Explore.unstar")); } }); diff --git a/src/lms/ui/explore/ReleaseView.cpp b/src/lms/ui/explore/ReleaseView.cpp index e2cfec0d..816cd0c4 100644 --- a/src/lms/ui/explore/ReleaseView.cpp +++ b/src/lms/ui/explore/ReleaseView.cpp @@ -217,9 +217,15 @@ Release::refreshView() if (!wApp->internalPathMatches("/release/")) return; - clear(); - const auto releaseId {extractReleaseIdFromInternalPath()}; + + // consider everything is up to date is the same release is being rendered + if (releaseId && *releaseId == _releaseId) + return; + + clear(); + _releaseId = {}; + if (!releaseId) throw ReleaseNotFoundException {}; @@ -232,6 +238,7 @@ Release::refreshView() throw ReleaseNotFoundException {}; LmsApp->setTitle(release->getName()); + _releaseId = *releaseId; refreshCopyright(release); refreshLinks(release); @@ -281,50 +288,50 @@ Release::refreshView() bindNew("play-btn", Wt::WString::tr("Lms.Explore.play"), Wt::TextFormat::XHTML) ->clicked().connect([=] { - _playQueueController.processCommand(PlayQueueController::Command::Play, {*releaseId}); + _playQueueController.processCommand(PlayQueueController::Command::Play, {_releaseId}); }); bindNew("play-shuffled", Wt::WString::tr("Lms.Explore.play-shuffled"), Wt::TextFormat::Plain) ->clicked().connect([=] { - _playQueueController.processCommand(PlayQueueController::Command::PlayShuffled, {*releaseId}); + _playQueueController.processCommand(PlayQueueController::Command::PlayShuffled, {_releaseId}); }); bindNew("play-next", Wt::WString::tr("Lms.Explore.play-next"), Wt::TextFormat::Plain) ->clicked().connect([=] { - _playQueueController.processCommand(PlayQueueController::Command::PlayNext, {*releaseId}); + _playQueueController.processCommand(PlayQueueController::Command::PlayNext, {_releaseId}); }); bindNew("play-last", Wt::WString::tr("Lms.Explore.play-last"), Wt::TextFormat::Plain) ->clicked().connect([=] { - _playQueueController.processCommand(PlayQueueController::Command::PlayOrAddLast, {*releaseId}); + _playQueueController.processCommand(PlayQueueController::Command::PlayOrAddLast, {_releaseId}); }); bindNew("download", Wt::WString::tr("Lms.Explore.download")) - ->setLink(Wt::WLink {std::make_unique(*releaseId)}); + ->setLink(Wt::WLink {std::make_unique(_releaseId)}); bindNew("release-info", Wt::WString::tr("Lms.Explore.release-info")) ->clicked().connect([=] { - showReleaseInfoModal(*releaseId); + showReleaseInfoModal(_releaseId); }); { - auto isStarred {[=] { return Service::get()->isStarred(LmsApp->getUserId(), *releaseId); }}; + auto isStarred {[=] { return Service::get()->isStarred(LmsApp->getUserId(), _releaseId); }}; Wt::WPushButton* starBtn {bindNew("star", Wt::WString::tr(isStarred() ? "Lms.Explore.unstar" : "Lms.Explore.star"))}; starBtn->clicked().connect([=] { if (isStarred()) { - Service::get()->unstar(LmsApp->getUserId(), *releaseId); + Service::get()->unstar(LmsApp->getUserId(), _releaseId); starBtn->setText(Wt::WString::tr("Lms.Explore.star")); } else { - Service::get()->star(LmsApp->getUserId(), *releaseId); + Service::get()->star(LmsApp->getUserId(), _releaseId); starBtn->setText(Wt::WString::tr("Lms.Explore.unstar")); } }); @@ -373,7 +380,7 @@ Release::refreshView() }; Database::Track::FindParameters params; - params.setRelease(*releaseId); + params.setRelease(_releaseId); params.setSortMethod(Database::TrackSortMethod::Release); params.setClusters(_filters.getClusterIds()); diff --git a/src/lms/ui/explore/ReleaseView.hpp b/src/lms/ui/explore/ReleaseView.hpp index 91964f33..270f5ed3 100644 --- a/src/lms/ui/explore/ReleaseView.hpp +++ b/src/lms/ui/explore/ReleaseView.hpp @@ -47,6 +47,7 @@ namespace UserInterface Filters& _filters; PlayQueueController& _playQueueController; + Database::ReleaseId _releaseId; }; } // namespace UserInterface