CollectionModel: Don't process model updates when loading

This commit is contained in:
Jonas Kvinge 2024-06-14 18:40:52 +02:00
parent 076d065f7c
commit f596695f61
2 changed files with 25 additions and 2 deletions

View File

@ -95,7 +95,8 @@ CollectionModel::CollectionModel(SharedPtr<CollectionBackend> 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<CollectionItem*> 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<CollectionItem*> 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 {

View File

@ -292,6 +292,8 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
int total_artist_count_;
int total_album_count_;
bool loading_;
QQueue<CollectionModelUpdate> updates_;
// Keyed on database ID