From f596695f61416129375d2dcfd62bdebb88f518d4 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 14 Jun 2024 18:40:52 +0200 Subject: [PATCH] CollectionModel: Don't process model updates when loading --- src/collection/collectionmodel.cpp | 25 +++++++++++++++++++++++-- src/collection/collectionmodel.h | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/collection/collectionmodel.cpp b/src/collection/collectionmodel.cpp index 628e6e4b4..b16089cb0 100644 --- a/src/collection/collectionmodel.cpp +++ b/src/collection/collectionmodel.cpp @@ -95,7 +95,8 @@ CollectionModel::CollectionModel(SharedPtr backend, Applicati use_disk_cache_(false), total_song_count_(0), total_artist_count_(0), - total_album_count_(0) { + total_album_count_(0), + loading_(false) { filter_->setSourceModel(this); filter_->setSortRole(Role_SortText); @@ -196,6 +197,12 @@ void CollectionModel::EndReset() { void CollectionModel::Reload() { + loading_ = true; + if (timer_reload_->isActive()) { + timer_reload_->stop(); + } + updates_.clear(); + options_active_ = options_current_; BeginReset(); @@ -467,7 +474,7 @@ void CollectionModel::ScheduleRemoveSongs(const SongList &songs) { void CollectionModel::ProcessUpdate() { - if (updates_.isEmpty()) { + if (loading_ || updates_.isEmpty()) { timer_update_->stop(); return; } @@ -497,6 +504,8 @@ void CollectionModel::ProcessUpdate() { void CollectionModel::AddReAddOrUpdateSongsInternal(const SongList &songs) { + if (loading_) return; + SongList songs_added; SongList songs_removed; SongList songs_updated; @@ -535,6 +544,8 @@ void CollectionModel::AddReAddOrUpdateSongsInternal(const SongList &songs) { void CollectionModel::AddSongsInternal(const SongList &songs) { + if (loading_) return; + for (const Song &song : songs) { // Sanity check to make sure we don't add songs that are outside the user's filter @@ -576,6 +587,8 @@ void CollectionModel::AddSongsInternal(const SongList &songs) { void CollectionModel::UpdateSongsInternal(const SongList &songs) { + if (loading_) return; + QList album_parents; for (const Song &new_song : songs) { @@ -618,6 +631,8 @@ void CollectionModel::UpdateSongsInternal(const SongList &songs) { void CollectionModel::RemoveSongsInternal(const SongList &songs) { + if (loading_) return; + // Delete the actual song nodes first, keeping track of each parent so we might check to see if they're empty later. QSet parents; for (const Song &song : songs) { @@ -833,6 +848,12 @@ void CollectionModel::LoadSongsFromSqlAsyncFinished() { ScheduleAddSongs(songs); EndReset(); + loading_ = false; + + if (!updates_.isEmpty() && !timer_update_->isActive()) { + timer_update_->start(); + } + } QString CollectionModel::AlbumIconPixmapCacheKey(const QModelIndex &idx) const { diff --git a/src/collection/collectionmodel.h b/src/collection/collectionmodel.h index 1299e532c..5dbe7f781 100644 --- a/src/collection/collectionmodel.h +++ b/src/collection/collectionmodel.h @@ -292,6 +292,8 @@ class CollectionModel : public SimpleTreeModel { int total_artist_count_; int total_album_count_; + bool loading_; + QQueue updates_; // Keyed on database ID