CollectionModel: Don't process model updates when loading
This commit is contained in:
@@ -95,7 +95,8 @@ CollectionModel::CollectionModel(SharedPtr<CollectionBackend> backend, Applicati
|
|||||||
use_disk_cache_(false),
|
use_disk_cache_(false),
|
||||||
total_song_count_(0),
|
total_song_count_(0),
|
||||||
total_artist_count_(0),
|
total_artist_count_(0),
|
||||||
total_album_count_(0) {
|
total_album_count_(0),
|
||||||
|
loading_(false) {
|
||||||
|
|
||||||
filter_->setSourceModel(this);
|
filter_->setSourceModel(this);
|
||||||
filter_->setSortRole(Role_SortText);
|
filter_->setSortRole(Role_SortText);
|
||||||
@@ -196,6 +197,12 @@ void CollectionModel::EndReset() {
|
|||||||
|
|
||||||
void CollectionModel::Reload() {
|
void CollectionModel::Reload() {
|
||||||
|
|
||||||
|
loading_ = true;
|
||||||
|
if (timer_reload_->isActive()) {
|
||||||
|
timer_reload_->stop();
|
||||||
|
}
|
||||||
|
updates_.clear();
|
||||||
|
|
||||||
options_active_ = options_current_;
|
options_active_ = options_current_;
|
||||||
|
|
||||||
BeginReset();
|
BeginReset();
|
||||||
@@ -467,7 +474,7 @@ void CollectionModel::ScheduleRemoveSongs(const SongList &songs) {
|
|||||||
|
|
||||||
void CollectionModel::ProcessUpdate() {
|
void CollectionModel::ProcessUpdate() {
|
||||||
|
|
||||||
if (updates_.isEmpty()) {
|
if (loading_ || updates_.isEmpty()) {
|
||||||
timer_update_->stop();
|
timer_update_->stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -497,6 +504,8 @@ void CollectionModel::ProcessUpdate() {
|
|||||||
|
|
||||||
void CollectionModel::AddReAddOrUpdateSongsInternal(const SongList &songs) {
|
void CollectionModel::AddReAddOrUpdateSongsInternal(const SongList &songs) {
|
||||||
|
|
||||||
|
if (loading_) return;
|
||||||
|
|
||||||
SongList songs_added;
|
SongList songs_added;
|
||||||
SongList songs_removed;
|
SongList songs_removed;
|
||||||
SongList songs_updated;
|
SongList songs_updated;
|
||||||
@@ -535,6 +544,8 @@ void CollectionModel::AddReAddOrUpdateSongsInternal(const SongList &songs) {
|
|||||||
|
|
||||||
void CollectionModel::AddSongsInternal(const SongList &songs) {
|
void CollectionModel::AddSongsInternal(const SongList &songs) {
|
||||||
|
|
||||||
|
if (loading_) return;
|
||||||
|
|
||||||
for (const Song &song : songs) {
|
for (const Song &song : songs) {
|
||||||
|
|
||||||
// Sanity check to make sure we don't add songs that are outside the user's filter
|
// 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) {
|
void CollectionModel::UpdateSongsInternal(const SongList &songs) {
|
||||||
|
|
||||||
|
if (loading_) return;
|
||||||
|
|
||||||
QList<CollectionItem*> album_parents;
|
QList<CollectionItem*> album_parents;
|
||||||
|
|
||||||
for (const Song &new_song : songs) {
|
for (const Song &new_song : songs) {
|
||||||
@@ -618,6 +631,8 @@ void CollectionModel::UpdateSongsInternal(const SongList &songs) {
|
|||||||
|
|
||||||
void CollectionModel::RemoveSongsInternal(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.
|
// 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;
|
QSet<CollectionItem*> parents;
|
||||||
for (const Song &song : songs) {
|
for (const Song &song : songs) {
|
||||||
@@ -833,6 +848,12 @@ void CollectionModel::LoadSongsFromSqlAsyncFinished() {
|
|||||||
ScheduleAddSongs(songs);
|
ScheduleAddSongs(songs);
|
||||||
EndReset();
|
EndReset();
|
||||||
|
|
||||||
|
loading_ = false;
|
||||||
|
|
||||||
|
if (!updates_.isEmpty() && !timer_update_->isActive()) {
|
||||||
|
timer_update_->start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CollectionModel::AlbumIconPixmapCacheKey(const QModelIndex &idx) const {
|
QString CollectionModel::AlbumIconPixmapCacheKey(const QModelIndex &idx) const {
|
||||||
|
|||||||
@@ -292,6 +292,8 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
|||||||
int total_artist_count_;
|
int total_artist_count_;
|
||||||
int total_album_count_;
|
int total_album_count_;
|
||||||
|
|
||||||
|
bool loading_;
|
||||||
|
|
||||||
QQueue<CollectionModelUpdate> updates_;
|
QQueue<CollectionModelUpdate> updates_;
|
||||||
|
|
||||||
// Keyed on database ID
|
// Keyed on database ID
|
||||||
|
|||||||
Reference in New Issue
Block a user