From caa7d8a128bdf9929917bfab4eef3c0444b1e473 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Sat, 27 Mar 2010 16:18:25 +0100 Subject: [PATCH] much faster deleting of messages from LocalStatus After tens of thousands of messages on the IMAP server were deleted it takes offlineimap extremely long time (several hours of high CPU usage) to delete them locally. It spends almost all the time modifying LocalStatus. It processes the messages one by one, rewriting the folder's status file in LocalStatus after each message. It is much more efficient to save the status file only once, after removing all the messages from the messagelist. Deleting lots of messages now takes seconds instead of hours. This should solve Debian bug #518093: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=518093 Signed-off-by: Michal Schmidt --- offlineimap/folder/LocalStatus.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py index 9f2cf88..157989d 100644 --- a/offlineimap/folder/LocalStatus.py +++ b/offlineimap/folder/LocalStatus.py @@ -141,7 +141,14 @@ class LocalStatusFolder(BaseFolder): self.autosave() def deletemessage(self, uid): - if not uid in self.messagelist: + self.deletemessages([uid]) + + def deletemessages(self, uidlist): + # Weed out ones not in self.messagelist + uidlist = [uid for uid in uidlist if uid in self.messagelist] + if not len(uidlist): return - del(self.messagelist[uid]) + + for uid in uidlist: + del(self.messagelist[uid]) self.autosave()