1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-22 16:59:58 +01:00

Cache playlist guids to speed up reloading

This commit is contained in:
Leo Franchi 2011-05-02 22:14:45 -04:00
parent aec8c97eac
commit 0f47027c9c
2 changed files with 13 additions and 2 deletions

View File

@ -48,9 +48,17 @@ WelcomePlaylistModel::loadFromSettings()
for( int i = playlist_guids.size() - 1; i >= 0; i-- )
{
qDebug() << "loading playlist" << playlist_guids[i];
Tomahawk::playlist_ptr pl = Tomahawk::Playlist::load( playlist_guids[i] );
if ( !pl.isNull() )
playlist_ptr pl = m_cached.value( playlist_guids[i], playlist_ptr() );
if( pl.isNull() )
pl = Tomahawk::Playlist::load( playlist_guids[i] );
if ( !pl.isNull() ) {
m_recplaylists << pl;
if( !m_cached.contains( playlist_guids[i] ) )
m_cached[playlist_guids[i]] = pl;
}
}
endResetModel();
@ -108,6 +116,8 @@ WelcomePlaylistModel::onPlaylistsRemoved( QList< playlist_ptr > playlists )
foreach( const playlist_ptr& pl, playlists ) {
if( m_recplaylists.contains( pl ) ) {
m_artists.remove( pl );
m_cached.remove( pl->guid() );
int idx = m_recplaylists.indexOf( pl );
beginRemoveRows( QModelIndex(), idx, idx );
m_recplaylists.removeAt( idx );

View File

@ -50,6 +50,7 @@ private slots:
private:
QList< Tomahawk::playlist_ptr > m_recplaylists;
QHash< QString, Tomahawk::playlist_ptr > m_cached;
mutable QHash< Tomahawk::playlist_ptr, QString > m_artists;
};