A new user interface for you! Read more...

File 0007-Fix-performance-issue-with-large-podcast-feeds.patch of Package amarok

From a5b0f2afe1b62de636798b7452e4e3abae86db72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Frank=20Meerk=C3=B6tter?= <frank@meerkoetter.org>
Date: Sun, 8 Sep 2013 19:59:57 +0200
Subject: [PATCH 1/1] Fix performance issue with large podcast feeds.

The podcast UI was very slow with channels with a large
number of episodes (1000+).

The root cause was that SqlPodcastChannel::tracks() was implemented
in such a way that it was expensive to call it. Unfortunately
it is extensively called by the PlaylistBrower...

BUG: 283022
REVIEW: 112417
---
 src/browsers/playlistbrowser/PlaylistBrowserModel.cpp |  2 +-
 src/core-impl/podcasts/sql/SqlPodcastMeta.cpp         | 13 +++++++++++--
 src/core-impl/podcasts/sql/SqlPodcastMeta.h           |  2 ++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp b/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp
index 281694a..32d3d8b 100644
--- a/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp
+++ b/src/browsers/playlistbrowser/PlaylistBrowserModel.cpp
@@ -308,7 +308,7 @@ PlaylistBrowserModel::rowCount( const QModelIndex &parent ) const
     else if( !IS_TRACK(parent) )
     {
         Playlists::PlaylistPtr playlist = m_playlists.value( parent.internalId() );
-        return playlist->tracks().count();
+        return playlist->trackCount();
     }
 
     return 0;
diff --git a/src/core-impl/podcasts/sql/SqlPodcastMeta.cpp b/src/core-impl/podcasts/sql/SqlPodcastMeta.cpp
index 20bcaff..08690ea 100644
--- a/src/core-impl/podcasts/sql/SqlPodcastMeta.cpp
+++ b/src/core-impl/podcasts/sql/SqlPodcastMeta.cpp
@@ -527,6 +527,7 @@ SqlPodcastChannel::SqlPodcastChannel( SqlPodcastProvider *provider,
                                             const QStringList &result )
     : Podcasts::PodcastChannel()
     , m_episodesLoaded( false )
+    , m_trackCacheIsValid( false )
     , m_provider( provider )
 {
     SqlStorage *sqlStorage = CollectionManager::instance()->sqlStorage();
@@ -553,6 +554,7 @@ SqlPodcastChannel::SqlPodcastChannel( Podcasts::SqlPodcastProvider *provider,
                                             Podcasts::PodcastChannelPtr channel )
     : Podcasts::PodcastChannel()
     , m_dbId( 0 )
+    , m_trackCacheIsValid( false )
     , m_provider( provider )
     , m_filenameLayout( "%default%" )
 {
@@ -731,7 +733,7 @@ SqlPodcastChannel::addEpisode( PodcastEpisodePtr episode )
     notifyObserversTrackAdded( Meta::TrackPtr::dynamicCast( sqlEpisode ), i );
 
     applyPurge();
-
+    m_trackCacheIsValid = false;
     return PodcastEpisodePtr::dynamicCast( sqlEpisode );
 }
 
@@ -759,6 +761,7 @@ SqlPodcastChannel::applyPurge()
                     purgeIndex++;
             }
         }
+        m_trackCacheIsValid = false;
     }
 }
 
@@ -813,6 +816,7 @@ SqlPodcastChannel::deleteFromDb()
        sqlEpisode->deleteFromDb();
        m_episodes.removeOne( sqlEpisode );
     }
+    m_trackCacheIsValid = false;
 
     sqlStorage->query(
         QString( "DELETE FROM podcastchannels WHERE id = %1;" ).arg( dbId() ) );
@@ -868,12 +872,17 @@ SqlPodcastChannel::loadEpisodes()
     }
 
     m_episodesLoaded = true;
+    m_trackCacheIsValid = false;
 }
 
 Meta::TrackList
 Podcasts::SqlPodcastChannel::tracks()
 {
-    return Podcasts::SqlPodcastEpisode::toTrackList( m_episodes );
+    if ( !m_trackCacheIsValid ) {
+        m_episodesAsTracksCache = Podcasts::SqlPodcastEpisode::toTrackList( m_episodes );
+        m_trackCacheIsValid = true;
+    }
+    return m_episodesAsTracksCache;
 }
 
 void
diff --git a/src/core-impl/podcasts/sql/SqlPodcastMeta.h b/src/core-impl/podcasts/sql/SqlPodcastMeta.h
index 02a18d3..ed346ba 100644
--- a/src/core-impl/podcasts/sql/SqlPodcastMeta.h
+++ b/src/core-impl/podcasts/sql/SqlPodcastMeta.h
@@ -155,6 +155,8 @@ class SqlPodcastChannel : public Podcasts::PodcastChannel
         bool m_episodesLoaded;
 
         SqlPodcastEpisodeList m_episodes;
+        bool m_trackCacheIsValid;
+        Meta::TrackList m_episodesAsTracksCache;
         SqlPodcastProvider *m_provider;
         QString m_filenameLayout; //specifies filename layout for episodes
 };
-- 
1.8.4