[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    [PATCH] Compress emits to gui.
From:       Mario Teijeiro Otero <emeteo () escomposlinux ! org>
Date:       2005-04-14 23:42:43
Message-ID: 200504150142.51502.emeteo () escomposlinux ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi,

	I am with dimap and my imap server reside on the lan. I notice that a 
"Refresh cache" or a checking mail with a lot of new messages eat the 100% of 
cpu.
	I found that the problems is related with the gui refresh, because the gui is 
refreshed with each mail that arrives ( kmheaders, kmfoldertree and 
statusBar ). With a suggestion of Till I compress the signals "msgAdded" in
FolderStorage::emitMsgAddedSigals getting good results, I did the same with 
the signal numUnreadMsgsChanged because this is connected with the refresh of 
status bar. 
	
	With this patch, the CPU keeps at 40% when the cache is refresh when before 
raise to 100%.

	Please, have a look and test it. it likes works fine  and don't broke 
anything (to me), but only god knows. 

	Regards

["emits_delayed.diff" (text/x-diff)]

? .folderstorage.cpp.swp
? .kmfoldercachedimap.cpp.swp
? .kmmainwin.rc.swp
? .kmreadermainwin.rc.swp
? pics/quotecollapse.png
? pics/quoteexpand.png
Index: cachedimapjob.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/cachedimapjob.cpp,v
retrieving revision 1.63
diff -u -p -r1.63 cachedimapjob.cpp
--- cachedimapjob.cpp	8 Mar 2005 14:43:35 -0000	1.63
+++ cachedimapjob.cpp	14 Apr 2005 23:21:30 -0000
@@ -290,9 +290,11 @@ void CachedImapJob::slotGetNextMessage(K
     mSentBytes += size;
     emit progress( mSentBytes, mTotalBytes );
     mAccount->removeJob(it);
-  }
+  } else
+    mFolder->quiet( true );
 
   if( mMsgsForDownload.isEmpty() ) {
+    mFolder->quiet( false );
     delete this;
     return;
   }
Index: folderstorage.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/folderstorage.cpp,v
retrieving revision 1.49
diff -u -p -r1.49 folderstorage.cpp
--- folderstorage.cpp	31 Mar 2005 20:37:53 -0000	1.49
+++ folderstorage.cpp	14 Apr 2005 23:21:34 -0000
@@ -61,7 +61,7 @@ using KMail::ListJob;
 //-----------------------------------------------------------------------------
 
 FolderStorage::FolderStorage( KMFolder* folder, const char* aName )
-  : QObject( folder, aName ), mFolder( folder )
+  : QObject( folder, aName ), mFolder( folder ), mQuietTimer( 0L )
 {
   mOpenCount      = 0;
   mQuiet	  = 0;
@@ -82,6 +82,7 @@ FolderStorage::FolderStorage( KMFolder* 
   mDirtyTimer = new QTimer(this);
   connect(mDirtyTimer, SIGNAL(timeout()),
 	  this, SLOT(updateIndex()));
+  
   mHasChildren = HasNoChildren;
   mContentsType = KMail::ContentsTypeMail;
 }
@@ -192,15 +193,32 @@ void FolderStorage::markUnreadAsRead()
 //-----------------------------------------------------------------------------
 void FolderStorage::quiet(bool beQuiet)
 {
+
   if (beQuiet)
+  {
+    /* Allocate the timer here to don't have one timer for each folder. BTW,
+     * a timer is created when a folder is checked
+     */
+    if ( !mQuietTimer ) { 
+      mQuietTimer = new QTimer( this );
+      connect( mQuietTimer, SIGNAL( timeout() ),
+      this, SLOT( slotQuietTimer() ) );
+    }
     mQuiet++;
-  else {
+  } else {
     mQuiet--;
     if (mQuiet <= 0)
     {
+      delete mQuietTimer;
+      mQuietTimer=0L;
+
       mQuiet = 0;
-      if (mChanged)
+      if (mChanged) {
        emit changed();
+       // Don't hurt emit this if the mUnreadMsg really don't change
+       // We emit it here, because this signal is delayed if mQuite >0
+       emit numUnreadMsgsChanged( folder() );
+      }
       mChanged = FALSE;
     }
   }
@@ -245,6 +263,13 @@ int FolderStorage::expungeOldMsg(int day
   return msgnb;
 }
 
+//------------------------------------------
+void FolderStorage::slotQuietTimer()
+{
+  kdDebug(5006) << "FolderStorage::slotQuietTimer()" << endl;
+  emit changed();
+  mChanged=false;
+}
 //-----------------------------------------------------------------------------
 void FolderStorage::emitMsgAddedSignals(int idx)
 {
@@ -252,6 +277,11 @@ void FolderStorage::emitMsgAddedSignals(
   if (!mQuiet) {
     emit msgAdded(idx);
   } else {
+    /** Restart always the timer or not. BTW we get a kmheaders refresh
+     * each 3 seg.?*/
+    if ( !mQuietTimer->isActive() ) {
+      mQuietTimer->start( 3000 );
+    }
     mChanged=true;
   }
   emit msgAdded( folder(), serNum );
@@ -359,7 +389,16 @@ void FolderStorage::removeMsg(int idx, b
   if (mb->isUnread() || mb->isNew() ||
       (folder() == kmkernel->outboxFolder())) {
     --mUnreadMsgs;
-    emit numUnreadMsgsChanged( folder() );
+    if ( !mQuiet ) {
+//      kdDebug( 5006 ) << "FolderStorage::msgStatusChanged" << endl;
+      emit numUnreadMsgsChanged( folder() );
+    }else{
+      if ( !mQuietTimer->isActive() ) {
+        kdDebug( 5006 )<< "QuietTimer started" << endl;
+        mQuietTimer->start( 3000 );
+      }
+      mChanged = true;
+    }
   }
   --mTotalMsgs;
 
@@ -388,7 +427,16 @@ KMMessage* FolderStorage::take(int idx)
   if (msg->isUnread() || msg->isNew() ||
       ( folder() == kmkernel->outboxFolder() )) {
     --mUnreadMsgs;
-    emit numUnreadMsgsChanged( folder() );
+    if ( !mQuiet ) {
+      kdDebug( 5006 ) << "FolderStorage::msgStatusChanged" << endl;
+      emit numUnreadMsgsChanged( folder() );
+    }else{
+      if ( !mQuietTimer->isActive() ) {
+        kdDebug( 5006 )<< "QuietTimer started" << endl;
+        mQuietTimer->start( 3000 );
+      }
+      mChanged = true;
+    }
   }
   --mTotalMsgs;
   msg->setParent(0);
@@ -800,10 +848,16 @@ void FolderStorage::msgStatusChanged(con
   if (deltaUnread != 0) {
     if (mUnreadMsgs < 0) mUnreadMsgs = 0;
     mUnreadMsgs += deltaUnread;
-    if ( !mQuiet )
+    if ( !mQuiet ) {
+      kdDebug( 5006 ) << "FolderStorage::msgStatusChanged" << endl;
       emit numUnreadMsgsChanged( folder() );
-    else
+    }else{
+      if ( !mQuietTimer->isActive() ) {
+        kdDebug( 5006 )<< "QuietTimer started" << endl;
+        mQuietTimer->start( 3000 );
+      }
       mChanged = true;
+    }
     Q_UINT32 serNum = kmkernel->msgDict()->getMsgSerNum(folder(), idx);
     emit msgChanged( folder(), serNum, deltaUnread );
   }
@@ -816,8 +870,14 @@ void FolderStorage::headerOfMsgChanged(c
     idx = aMsg->parent()->find( aMsg );
   if (idx >= 0 && !mQuiet)
     emit msgHeaderChanged(folder(), idx);
-  else
+  else{
+    if ( !mQuietTimer->isActive() ) {
+      kdDebug( 5006 )<< "QuietTimer started" << endl;
+      mQuietTimer->start( 3000 );
+    }
+
     mChanged = true;
+  }
 }
 
 //-----------------------------------------------------------------------------
@@ -860,6 +920,7 @@ void FolderStorage::correctUnreadMsgsCou
 {
   open();
   close();
+  kdDebug( 5006 ) << "FolderStorage::correctUnreadMsgsCount" << endl;
   emit numUnreadMsgsChanged( folder() );
 }
 
Index: folderstorage.h
===================================================================
RCS file: /home/kde/kdepim/kmail/folderstorage.h,v
retrieving revision 1.43
diff -u -p -r1.43 folderstorage.h
--- folderstorage.h	16 Feb 2005 20:13:19 -0000	1.43
+++ folderstorage.h	14 Apr 2005 23:21:35 -0000
@@ -507,6 +507,8 @@ public slots:
   /** Add a copy of the message to the folder after it has been retrieved
       from an IMAP server */
   virtual void reallyAddCopyOfMsg(KMMessage* aMsg);
+  /**  */
+  void slotQuietTimer();
 
 protected slots:
   virtual void removeJob( QObject* );
@@ -592,6 +594,8 @@ protected:
 
   KMFolder* mFolder;
 
+  QTimer * mQuietTimer;
+
   int mCurrentSearchedMsg;
   KMSearchPattern* mSearchPattern;
 };
Index: kmfoldercachedimap.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmfoldercachedimap.cpp,v
retrieving revision 1.171
diff -u -p -r1.171 kmfoldercachedimap.cpp
--- kmfoldercachedimap.cpp	29 Mar 2005 22:24:27 -0000	1.171
+++ kmfoldercachedimap.cpp	14 Apr 2005 23:21:37 -0000
@@ -313,7 +313,7 @@ void KMFolderCachedImap::reloadUidMap()
     KMMsgBase *msg = getMsgBase( i );
     if( !msg ) continue;
     ulong uid = msg->UID();
-    kdDebug(5006) << "Inserting: " << i << " with uid: " << uid << endl;
+    //kdDebug(5006) << "Inserting: " << i << " with uid: " << uid << endl;
     uidMap.insert( uid, i );
   }
   close();
Index: kmfoldermaildir.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmfoldermaildir.cpp,v
retrieving revision 1.101
diff -u -p -r1.101 kmfoldermaildir.cpp
--- kmfoldermaildir.cpp	31 Mar 2005 20:37:52 -0000	1.101
+++ kmfoldermaildir.cpp	14 Apr 2005 23:21:37 -0000
@@ -465,7 +465,16 @@ if( fileD0.open( IO_WriteOnly ) ) {
       mUnreadMsgs = 1;
     else
       ++mUnreadMsgs;
-    emit numUnreadMsgsChanged( folder() );
+    if ( !mQuiet ) {
+      kdDebug( 5006 ) << "FolderStorage::msgStatusChanged" << endl;
+      emit numUnreadMsgsChanged( folder() );
+    }else{
+      if ( !mQuietTimer->isActive() ) {
+        kdDebug( 5006 )<< "QuietTimer started" << endl;
+        mQuietTimer->start( 3000 );
+      }
+      mChanged = true;
+    }
   }
   ++mTotalMsgs;
 
Index: kmfoldertree.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmfoldertree.cpp,v
retrieving revision 1.355
diff -u -p -r1.355 kmfoldertree.cpp
--- kmfoldertree.cpp	6 Apr 2005 06:49:05 -0000	1.355
+++ kmfoldertree.cpp	14 Apr 2005 23:21:38 -0000
@@ -291,6 +291,8 @@ KMFolderTree::KMFolderTree( KMMainWidget
   mMainWidget = mainWidget;
   mReloading = false;
 
+  mUpdateCountTimer= new QTimer( this );
+
   addAcceptableDropMimetype(MailListDrag::format(), false);
 
   int namecol = addColumn( i18n("Folder"), 250 );
@@ -313,6 +315,9 @@ KMFolderTree::KMFolderTree( KMMainWidget
 // connects all needed signals to their slots
 void KMFolderTree::connectSignals()
 {
+  connect( mUpdateCountTimer, SIGNAL(timeout()),
+          this, SLOT(slotUpdateCountTimeout()) );
+
   connect(&mUpdateTimer, SIGNAL(timeout()),
           this, SLOT(delayedUpdate()));
 
@@ -534,7 +539,7 @@ void KMFolderTree::reload(bool openFolde
                fti,SLOT(slotNameChanged()));
     connect(fti->folder(),SIGNAL(nameChanged()),
             fti,SLOT(slotNameChanged()));
-
+/*
     if (fti->folder()->folderType() == KMFolderTypeImap) {
       // imap-only
       KMFolderImap *imapFolder =
@@ -543,23 +548,23 @@ void KMFolderTree::reload(bool openFolde
           this,SLOT(slotUpdateCounts(KMFolderImap*, bool)));
       connect( imapFolder, SIGNAL(folderComplete(KMFolderImap*, bool)),
           this,SLOT(slotUpdateCounts(KMFolderImap*, bool)));
-    } else {
+    } else*/ {
       // others-only, imap doesn't need this because of the folderComplete-signal
       // we want to be noticed of changes to update the unread/total columns
       disconnect(fti->folder(), SIGNAL(msgAdded(KMFolder*,Q_UINT32)),
-          this,SLOT(slotUpdateCounts(KMFolder*)));
+          this,SLOT(slotUpdateCountsDelayed(KMFolder*)));
       connect(fti->folder(), SIGNAL(msgAdded(KMFolder*,Q_UINT32)),
-          this,SLOT(slotUpdateCounts(KMFolder*)));
+          this,SLOT(slotUpdateCountsDelayed(KMFolder*)));
     }
 
     disconnect(fti->folder(), SIGNAL(numUnreadMsgsChanged(KMFolder*)),
-               this,SLOT(slotUpdateCounts(KMFolder*)));
+               this,SLOT(slotUpdateCountsDelayed(KMFolder*)));
     connect(fti->folder(), SIGNAL(numUnreadMsgsChanged(KMFolder*)),
-            this,SLOT(slotUpdateCounts(KMFolder*)));
+            this,SLOT(slotUpdateCountsDelayed(KMFolder*)));
     disconnect(fti->folder(), SIGNAL(msgRemoved(KMFolder*)),
-               this,SLOT(slotUpdateCounts(KMFolder*)));
+               this,SLOT(slotUpdateCountsDelayed(KMFolder*)));
     connect(fti->folder(), SIGNAL(msgRemoved(KMFolder*)),
-            this,SLOT(slotUpdateCounts(KMFolder*)));
+            this,SLOT(slotUpdateCountsDelayed(KMFolder*)));
 
     disconnect(fti->folder(), SIGNAL(shortcutChanged(KMFolder*)),
                mMainWidget, SLOT( slotShortcutChanged(KMFolder*)));
@@ -1455,8 +1460,39 @@ void KMFolderTree::slotUpdateCounts(KMFo
 }
 
 //-----------------------------------------------------------------------------
+void KMFolderTree::slotUpdateCountsDelayed(KMFolder * folder)
+{
+//  kdDebug(5006) << "KMFolderTree::slotUpdateCountsDelayed()" << endl;
+  if ( !mFolderToUpdateCount.contains( folder->idString() ) )
+  {
+//    kdDebug( 5006 )<< "adding " << folder->idString() << " to updateCountList " << endl;
+    mFolderToUpdateCount.insert( folder->idString(),folder );
+  }
+  if ( !mUpdateCountTimer->isActive() )
+    mUpdateCountTimer->start( 500 );
+}
+
+
+void KMFolderTree::slotUpdateCountTimeout()
+{
+  kdDebug(5006) << "KMFolderTree::slotUpdateCountTimeout()" << endl;
+
+
+  QMap<QString,KMFolder*>::iterator it;
+  for ( it= mFolderToUpdateCount.begin();
+      it!=mFolderToUpdateCount.end();
+      ++it )
+  {
+    slotUpdateCounts( it.data() );
+  }
+  mFolderToUpdateCount.clear();
+  mUpdateCountTimer->stop();
+
+}
+
 void KMFolderTree::slotUpdateCounts(KMFolder * folder)
 {
+  kdDebug(5006) << "KMFolderTree::slotUpdateCounts()" << endl;
   QListViewItem * current;
   if (folder)
     current = indexOfFolder(folder);
Index: kmfoldertree.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmfoldertree.h,v
retrieving revision 1.92
diff -u -p -r1.92 kmfoldertree.h
--- kmfoldertree.h	2 Feb 2005 21:25:24 -0000	1.92
+++ kmfoldertree.h	14 Apr 2005 23:21:39 -0000
@@ -268,6 +268,9 @@ protected slots:
   /** Update the total and unread columns (if available) */
   void slotUpdateCounts(KMFolder * folder);
   void slotUpdateCounts(KMFolderImap * folder, bool success = true);
+  /** Update the total and unread columns but delayed */
+  void slotUpdateCountsDelayed(KMFolder * folder);
+  void slotUpdateCountTimeout();
   void slotUpdateOneCount();
 
   /** slots for the unread/total-popup */
@@ -340,6 +343,9 @@ private:
   bool mReloading;
   QMap<const KMFolder*, KMFolderTreeItem*> mFolderToItem;
 
+  QTimer *mUpdateCountTimer;
+  QMap<QString,KMFolder*> mFolderToUpdateCount;
+
   /** Map menu id into a folder */
   KMMenuToFolder mMenuToFolder;
 };

[Attachment #8 (application/pgp-signature)]

_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic