Do Podcast updates on song change off main thread
Each time the song is changed, the podcast backend checks whether the new song is a podcast and, if so, mark it as listened to. This requires 1-2 db queries, so do it off the main thread. Time to change song before: 300 ms after: 50 ms usually, 80 ms sometimes
This commit is contained in:
parent
401f07c7cb
commit
3f9b5f4663
@ -39,6 +39,7 @@
|
||||
|
||||
#include <QMenu>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
const char* PodcastService::kServiceName = "Podcasts";
|
||||
const char* PodcastService::kSettingsGroup = "Podcasts";
|
||||
@ -60,8 +61,7 @@ PodcastService::PodcastService(Application* app, InternetModel* parent)
|
||||
proxy_(new PodcastSortProxyModel(this)),
|
||||
context_menu_(nullptr),
|
||||
root_(nullptr),
|
||||
organise_dialog_(new OrganiseDialog(app_->task_manager(),
|
||||
nullptr)) {
|
||||
organise_dialog_(new OrganiseDialog(app_->task_manager(), nullptr)) {
|
||||
icon_loader_->SetModel(model_);
|
||||
proxy_->setSourceModel(model_);
|
||||
proxy_->setDynamicSortFilter(true);
|
||||
@ -78,8 +78,8 @@ PodcastService::PodcastService(Application* app, InternetModel* parent)
|
||||
|
||||
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)),
|
||||
SLOT(CurrentSongChanged(Song)));
|
||||
connect(organise_dialog_.get(), SIGNAL(FileCopied(int)),
|
||||
this, SLOT(FileCopied(int)));
|
||||
connect(organise_dialog_.get(), SIGNAL(FileCopied(int)), this,
|
||||
SLOT(FileCopied(int)));
|
||||
}
|
||||
|
||||
PodcastService::~PodcastService() {}
|
||||
@ -602,6 +602,13 @@ void PodcastService::ShowConfig() {
|
||||
}
|
||||
|
||||
void PodcastService::CurrentSongChanged(const Song& metadata) {
|
||||
// This does two db queries, and we are called on every song change, so run
|
||||
// this off the main thread.
|
||||
QtConcurrent::run(this, &PodcastService::UpdatePodcastListenedStateAsync,
|
||||
metadata);
|
||||
}
|
||||
|
||||
void PodcastService::UpdatePodcastListenedStateAsync(const Song& metadata) {
|
||||
// Check whether this song is one of our podcast episodes.
|
||||
PodcastEpisode episode = backend_->GetEpisodeByUrlOrLocalUrl(metadata.url());
|
||||
if (!episode.is_valid()) return;
|
||||
|
@ -96,6 +96,7 @@ class PodcastService : public InternetService {
|
||||
private:
|
||||
void EnsureAddPodcastDialogCreated();
|
||||
|
||||
void UpdatePodcastListenedStateAsync(const Song& metadata);
|
||||
void PopulatePodcastList(QStandardItem* parent);
|
||||
void UpdatePodcastText(QStandardItem* item, int unlistened_count) const;
|
||||
void UpdateEpisodeText(
|
||||
|
Loading…
x
Reference in New Issue
Block a user