Fix pixmap cache in collection model
- Properly remove both from pixmap cache, pending art and pending cache keys when songs are deleted - Increase default pixmap cache - Clear pixmap cache when model is reset
This commit is contained in:
@@ -125,6 +125,8 @@ CollectionModel::CollectionModel(CollectionBackend *backend, Application *app, Q
|
|||||||
backend_->UpdateTotalArtistCountAsync();
|
backend_->UpdateTotalArtistCountAsync();
|
||||||
backend_->UpdateTotalAlbumCountAsync();
|
backend_->UpdateTotalAlbumCountAsync();
|
||||||
|
|
||||||
|
QPixmapCache::setCacheLimit(61440);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectionModel::~CollectionModel() { delete root_; }
|
CollectionModel::~CollectionModel() { delete root_; }
|
||||||
@@ -419,9 +421,21 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
|
|||||||
|
|
||||||
if (node->parent != root_) parents << node->parent;
|
if (node->parent != root_) parents << node->parent;
|
||||||
|
|
||||||
|
// Remove from pixmap cache
|
||||||
QModelIndex idx = ItemToIndex(node->parent);
|
QModelIndex idx = ItemToIndex(node->parent);
|
||||||
const QString cache_key = AlbumIconPixmapCacheKey(idx);
|
const QString cache_key = AlbumIconPixmapCacheKey(idx);
|
||||||
QPixmapCache::remove(cache_key);
|
QPixmapCache::remove(cache_key);
|
||||||
|
if (pending_cache_keys_.contains(cache_key)) pending_cache_keys_.remove(cache_key);
|
||||||
|
|
||||||
|
// Remove from pending art loading
|
||||||
|
QMapIterator<quint64, ItemAndCacheKey> i(pending_art_);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
if (i.value().first == node) {
|
||||||
|
pending_art_.remove(i.key());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
beginRemoveRows(idx, node->row, node->row);
|
beginRemoveRows(idx, node->row, node->row);
|
||||||
node->parent->Delete(node->row);
|
node->parent->Delete(node->row);
|
||||||
@@ -460,6 +474,22 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
|
|||||||
else
|
else
|
||||||
container_nodes_[node->container_level].remove(node->key);
|
container_nodes_[node->container_level].remove(node->key);
|
||||||
|
|
||||||
|
// Remove from pixmap cache
|
||||||
|
QModelIndex idx = ItemToIndex(node->parent);
|
||||||
|
const QString cache_key = AlbumIconPixmapCacheKey(idx);
|
||||||
|
QPixmapCache::remove(cache_key);
|
||||||
|
if (pending_cache_keys_.contains(cache_key)) pending_cache_keys_.remove(cache_key);
|
||||||
|
|
||||||
|
// Remove from pending art loading
|
||||||
|
QMapIterator<quint64, ItemAndCacheKey> i(pending_art_);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
if (i.value().first == node) {
|
||||||
|
pending_art_.remove(i.key());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// It was empty - delete it
|
// It was empty - delete it
|
||||||
beginRemoveRows(ItemToIndex(node->parent), node->row, node->row);
|
beginRemoveRows(ItemToIndex(node->parent), node->row, node->row);
|
||||||
node->parent->Delete(node->row);
|
node->parent->Delete(node->row);
|
||||||
@@ -567,6 +597,8 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, const QUrl &cover_url,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QModelIndex idx = ItemToIndex(item);
|
const QModelIndex idx = ItemToIndex(item);
|
||||||
|
if (!idx.isValid()) return;
|
||||||
|
|
||||||
emit dataChanged(idx, idx);
|
emit dataChanged(idx, idx);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -798,6 +830,8 @@ void CollectionModel::BeginReset() {
|
|||||||
container_nodes_[2].clear();
|
container_nodes_[2].clear();
|
||||||
divider_nodes_.clear();
|
divider_nodes_.clear();
|
||||||
pending_art_.clear();
|
pending_art_.clear();
|
||||||
|
pending_cache_keys_.clear();
|
||||||
|
QPixmapCache::clear();
|
||||||
|
|
||||||
root_ = new CollectionItem(this);
|
root_ = new CollectionItem(this);
|
||||||
root_->compilation_artist_node_ = nullptr;
|
root_->compilation_artist_node_ = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user