From ca012d3a81428b6bc74274ee036391c591477b0f Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Mon, 28 Mar 2011 10:19:19 -0400 Subject: [PATCH] Implement more efficient functions for the MappedUID case 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 Reviewed-and-tested-by: Vincent Beffara Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/UIDMaps.py | 25 +++++++++++++++++++++++-- 1 file 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)