From 29e9b7ab39c0f1589814d451204a105067f490ea Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Sun, 5 Jan 2014 16:07:03 +0100 Subject: [PATCH] Drop caches after having processed folders. This enhances a lot memory consumption when you have many folders to process. Signed-off-by: Giovanni Mascellani --- offlineimap/accounts.py | 4 ++++ offlineimap/folder/Base.py | 3 +++ offlineimap/folder/IMAP.py | 2 ++ offlineimap/folder/LocalStatus.py | 2 ++ offlineimap/folder/LocalStatusSQLite.py | 3 +++ offlineimap/folder/Maildir.py | 3 +++ offlineimap/folder/UIDMaps.py | 3 +++ 7 files changed, 20 insertions(+) diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 18a36fc..7adc3a4 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -491,3 +491,7 @@ def syncfolder(account, remotefolder, quick): ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \ (account, remotefolder.getvisiblename(), traceback.format_exc())) + finally: + for folder in ["statusfolder", "localfolder", "remotefolder"]: + if folder in locals(): + locals()[folder].dropmessagelistcache() diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 87e165c..7121231 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -247,6 +247,9 @@ class BaseFolder(object): raise NotImplementedError + def dropmessagelistcache(self): + raise NotImplementedException + def getmessagelist(self): """Gets the current message list. You must call cachemessagelist() before calling this function!""" diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 00afce0..c405431 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -250,6 +250,8 @@ class IMAPFolder(BaseFolder): rtime = imaplibutil.Internaldate2epoch(messagestr) self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime} + def dropmessagelistcache(self): + self.messagelist = None # Interface from BaseFolder def getmessagelist(self): diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py index ec34965..d3b6cf0 100644 --- a/offlineimap/folder/LocalStatus.py +++ b/offlineimap/folder/LocalStatus.py @@ -161,6 +161,8 @@ class LocalStatusFolder(BaseFolder): self.readstatus(file) file.close() + def dropmessagelistcache(self): + self.messagelist = None def save(self): """Save changed data to disk. For this backend it is the same as saveall.""" diff --git a/offlineimap/folder/LocalStatusSQLite.py b/offlineimap/folder/LocalStatusSQLite.py index 1b2adb0..9d7e559 100644 --- a/offlineimap/folder/LocalStatusSQLite.py +++ b/offlineimap/folder/LocalStatusSQLite.py @@ -203,6 +203,9 @@ class LocalStatusSQLiteFolder(BaseFolder): self.messagelist[uid]['labels'] = labels self.messagelist[uid]['mtime'] = row[2] + def dropmessagelistcache(self): + self.messagelist = None + # Interface from LocalStatusFolder def save(self): pass diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index af1e5ff..3a19cc3 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -220,6 +220,9 @@ class MaildirFolder(BaseFolder): if self.messagelist is None: self.messagelist = self._scanfolder() + def dropmessagelistcache(self): + self.messagelist = None + # Interface from BaseFolder def getmessagelist(self): return self.messagelist diff --git a/offlineimap/folder/UIDMaps.py b/offlineimap/folder/UIDMaps.py index e1a6f5f..eb4fbae 100644 --- a/offlineimap/folder/UIDMaps.py +++ b/offlineimap/folder/UIDMaps.py @@ -125,6 +125,9 @@ class MappedIMAPFolder(IMAPFolder): finally: self.maplock.release() + def dropmessagelistcache(self): + self._mb.dropmessagelistcache() + # Interface from BaseFolder def uidexists(self, ruid): """Checks if the (remote) UID exists in this Folder"""