[PATCH 1/2] Implement more efficient functions for the MappedUID case

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Mar 28 15:19:19 BST 2011


We are calling getmessagelist() internally a lot, e.g. just to check if
a UID exists (from uidexist()). This is a very expensive operation in
the UIDMapped case, as we reconstruct the whole messagelist dict every
single time, involving lots of copying etc.

So we provide more efficient implementations for the uidexists()
getmessageuidlist() and getmessagecount() functions that are fast in the
UIDMapped case. This should solve the performance regression that was
recently observed in the Mapped UID case.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/UIDMaps.py |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/offlineimap/folder/UIDMaps.py b/offlineimap/folder/UIDMaps.py
index 039a41d..43b28e4 100644
--- a/offlineimap/folder/UIDMaps.py
+++ b/offlineimap/folder/UIDMaps.py
@@ -107,9 +107,30 @@ class MappingFolderMixIn:
         finally:
             self.maplock.release()
 
+    def uidexists(self, ruid):
+        """Checks if the (remote) UID exists in this Folder"""
+        # This implementation overrides the one in BaseFolder, as it is
+        # much more efficient for the mapped case.
+        return ruid in self.r2l
+
+    def getmessageuidlist(self):
+        """Gets a list of (remote) UIDs.
+        You may have to call cachemessagelist() before calling this function!"""
+        # This implementation overrides the one in BaseFolder, as it is
+        # much more efficient for the mapped case.
+        return self.r2l.keys()
+
+    def getmessagecount(self):
+        """Gets the number of messages in this folder.
+        You may have to call cachemessagelist() before calling this function!"""
+        # This implementation overrides the one in BaseFolder, as it is
+        # much more efficient for the mapped case.
+        return len(self.r2l)
+
     def getmessagelist(self):
-        """Gets the current message list.
-        You must call cachemessagelist() before calling this function!"""
+        """Gets the current message list. This function's implementation
+        is quite expensive for the mapped UID case.  You must call
+        cachemessagelist() before calling this function!"""
 
         retval = {}
         localhash = self._mb.getmessagelist(self)
-- 
1.7.1





More information about the OfflineIMAP-project mailing list