Re: QtMoko IMAP sync patch

2013-04-18 Thread Radek Polak
On Thursday, April 18, 2013 12:26:14 AM Neil Jerram wrote:

 Hi Radek,
 
 Please would you consider the patch below?  It's a minor IMAP sync
 optimization, or more precisely quite a significant optimization but for
 a scenario that I would guess is pretty rare.  I've written more about
 it in the commit message.

Hi Neil,
applied and pushed, thanks!

Radek
___
Openmoko community mailing list
community@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/community


QtMoko IMAP sync patch

2013-04-17 Thread Neil Jerram
Hi Radek,

Please would you consider the patch below?  It's a minor IMAP sync
optimization, or more precisely quite a significant optimization but for
a scenario that I would guess is pretty rare.  I've written more about
it in the commit message.

Regards,
Neil

From ee6e35eaa7a9d848e3f84d2a970fe17e938e31f3 Mon Sep 17 00:00:00 2001
From: Neil Jerram n...@ossau.homelinux.net
Date: Fri, 28 Dec 2012 11:52:46 +
Subject: [PATCH] Optimise 'Removed' flagging of messages deleted from the
 IMAP server

On each IMAP server sync, if there are messages that exist on the
phone but have since been deleted from the IMAP server, or moved to a
different folder on the IMAP server, QtMoko adds the
QMailMessage::Removed flag to those messages.  Note that we don't
automatically delete those messages from the phone.

I once - not using QtMoko - moved several thousand older messages to
an OLD folder on my IMAP server.  After that I found that each
QtMoko IMAP server sync operation would take a lot of time and CPU,
and discovered this was because it was reflagging all of those moved
messages every time.  If we optimize the process by skipping messages
that already have the 'Removed' flag, it goes massively faster.
---
 src/tools/messageserver/imapclient.cpp |   23 +--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/tools/messageserver/imapclient.cpp b/src/tools/messageserver/imapclient.cpp
index 25536d0..9f10f5b 100644
--- a/src/tools/messageserver/imapclient.cpp
+++ b/src/tools/messageserver/imapclient.cpp
@@ -601,8 +601,15 @@ void ImapClient::searchCompleted()
 QMailAccount account(accountId);
 QStringList readElsewhereUids = account.serverUids(boxId, QMailMessage::ReadElsewhere);
 QStringList unreadElsewhereUids = account.serverUids(boxId, QMailMessage::ReadElsewhere, false);
+
+// deleted here means messages that have been deleted from the
+// phone (i.e. from the Qtopia database) but may still exist on
+// the IMAP server.  Code below will delete these from the IMAP
+// server too.
 QStringList deletedUids = account.deletedMessages(boxId);
 
+// The following generates a list of all the UIDs that have ever
+// previously been seen on the phone.
 QStringList storedUids = readElsewhereUids + unreadElsewhereUids + deletedUids;
 
 // New messages reported by the server that we don't yet have
@@ -623,8 +630,20 @@ void ImapClient::searchCompleted()
 // Messages marked read locally that the server reports are unseen
 _readUids = inFirstAndSecond(account.serverUids(boxId, QMailMessage::Read), _unseenUids);
 
-// Report any messages that are no longer returned by the server
-foreach (const QString uid, inFirstButNotSecond(storedUids, reportedUids))
+// If there are messages that exist on the phone but have
+// since been deleted from the IMAP server, add the
+// QMailMessage::Removed flag to those messages.  Note that we
+// don't automatically delete those messages from the phone.
+	//
+	// Optimize this a bit by skipping phone messages that already
+	// have the QMailMessage::Removed flag.  Otherwise, in a
+	// scenario where a lot of messages are deleted from the IMAP
+	// server - but still exist on the phone - all of those
+	// messages are reprocessed every time we sync with the IMAP
+	// server, and that can take significant time and CPU.
+foreach (const QString uid,
+		 inFirstButNotSecond(inFirstButNotSecond(storedUids, reportedUids),
+ account.serverUids(boxId, QMailMessage::Removed)))
 emit nonexistentMessage(uid, Client::Removed);
 
 // Update any messages that are reported read-elsewhere, that we didn't previously know about
-- 
1.7.10.4

___
Openmoko community mailing list
community@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/community