[Kde-pim] [PATCH 1/2] Prefetch collections before filtering if explicitly monitoring a collection.

Stephen Kelly steveire at gmail.com
Fri Feb 25 23:05:21 GMT 2011


---
 akonadi/monitor.cpp   |    3 +++
 akonadi/monitor_p.cpp |   28 ++++++++++++++++++++++++++++
 akonadi/monitor_p.h   |    8 ++++++++
 3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/akonadi/monitor.cpp b/akonadi/monitor.cpp
index d433ab6..4893112 100644
--- a/akonadi/monitor.cpp
+++ b/akonadi/monitor.cpp
@@ -66,6 +66,9 @@ void Monitor::setCollectionMonitored( const Collection &collection, bool monitor
   Q_D( Monitor );
   if ( monitored ) {
     d->collections << collection;
+    if ( collection != Collection::root() ) {
+      d->mCollectionFetchScope.setAncestorRetrieval( Akonadi::CollectionFetchScope::All );
+    }
   } else {
     d->collections.removeAll( collection );
     d->cleanOldNotifications();
diff --git a/akonadi/monitor_p.cpp b/akonadi/monitor_p.cpp
index 43f83fa..f4121d9 100644
--- a/akonadi/monitor_p.cpp
+++ b/akonadi/monitor_p.cpp
@@ -358,6 +358,31 @@ void MonitorPrivate::slotNotify( const NotificationMessage::List &msgs )
 {
   foreach ( const NotificationMessage &msg, msgs ) {
     invalidateCaches( msg );
+    prefetchIsReady( msg );
+    filterQueue.enqueue( msg );
+  }
+  filterMessages();
+}
+
+bool MonitorPrivate::prefetchIsReady( const NotificationMessage &msg )
+{
+  if ( !needPrefetch() )
+    return true;
+
+  const bool notCached = collectionCache.ensureCached( msg.parentCollection(), mCollectionFetchScope )
+      && ( msg.parentDestCollection() < 0 ) ? true :
+          collectionCache.ensureCached( msg.parentDestCollection(), mCollectionFetchScope );
+
+  return notCached;
+}
+
+void MonitorPrivate::filterMessages()
+{
+  while ( !filterQueue.isEmpty() ) {
+    const NotificationMessage msg = filterQueue.head();
+    if ( !prefetchIsReady( msg ) )
+      return;
+    filterQueue.dequeue();
     updatePendingStatistics( msg );
     if ( acceptNotification( msg ) ) {
       appendAndCompress( msg );
@@ -369,6 +394,9 @@ void MonitorPrivate::slotNotify( const NotificationMessage::List &msgs )
 
 void MonitorPrivate::dataAvailable()
 {
+  if ( !filterQueue.isEmpty() )
+    return filterMessages();
+
   while ( !pipeline.isEmpty() ) {
     const NotificationMessage msg = pipeline.head();
     if ( ensureDataAvailable( msg ) ) {
diff --git a/akonadi/monitor_p.h b/akonadi/monitor_p.h
index 2166fdf..cde1e97 100644
--- a/akonadi/monitor_p.h
+++ b/akonadi/monitor_p.h
@@ -67,6 +67,7 @@ class AKONADI_TESTS_EXPORT MonitorPrivate
     CollectionCache collectionCache;
     ItemCache itemCache;
     QQueue<NotificationMessage> pendingNotifications;
+    QQueue<NotificationMessage> filterQueue;
     QQueue<NotificationMessage> pipeline;
     bool fetchCollection;
     bool fetchCollectionStatistics;
@@ -94,6 +95,13 @@ class AKONADI_TESTS_EXPORT MonitorPrivate
     */
     void invalidateCache( const Collection &col );
 
+    bool needPrefetch() const {
+      return !(collections.isEmpty() || collections.contains(Collection::root()));
+    }
+
+    bool prefetchIsReady( const NotificationMessage &msg );
+    void filterMessages();
+
     virtual int pipelineSize() const;
 
     // private slots
-- 
1.7.4.rc1.8.gca2fb

_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list