Drop caches after having processed folders.

This enhances a lot memory consumption when you have many folders
to process.

Signed-off-by: Giovanni Mascellani <mascellani@poisson.phc.unipi.it>
This commit is contained in:
Giovanni Mascellani 2014-01-05 16:07:03 +01:00 committed by Nicolas Sebrecht
parent 63e499c6f2
commit 29e9b7ab39
7 changed files with 20 additions and 0 deletions

View File

@ -491,3 +491,7 @@ def syncfolder(account, remotefolder, quick):
ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \ ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \
(account, remotefolder.getvisiblename(), (account, remotefolder.getvisiblename(),
traceback.format_exc())) traceback.format_exc()))
finally:
for folder in ["statusfolder", "localfolder", "remotefolder"]:
if folder in locals():
locals()[folder].dropmessagelistcache()

View File

@ -247,6 +247,9 @@ class BaseFolder(object):
raise NotImplementedError raise NotImplementedError
def dropmessagelistcache(self):
raise NotImplementedException
def getmessagelist(self): def getmessagelist(self):
"""Gets the current message list. """Gets the current message list.
You must call cachemessagelist() before calling this function!""" You must call cachemessagelist() before calling this function!"""

View File

@ -250,6 +250,8 @@ class IMAPFolder(BaseFolder):
rtime = imaplibutil.Internaldate2epoch(messagestr) rtime = imaplibutil.Internaldate2epoch(messagestr)
self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime} self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime}
def dropmessagelistcache(self):
self.messagelist = None
# Interface from BaseFolder # Interface from BaseFolder
def getmessagelist(self): def getmessagelist(self):

View File

@ -161,6 +161,8 @@ class LocalStatusFolder(BaseFolder):
self.readstatus(file) self.readstatus(file)
file.close() file.close()
def dropmessagelistcache(self):
self.messagelist = None
def save(self): def save(self):
"""Save changed data to disk. For this backend it is the same as saveall.""" """Save changed data to disk. For this backend it is the same as saveall."""

View File

@ -203,6 +203,9 @@ class LocalStatusSQLiteFolder(BaseFolder):
self.messagelist[uid]['labels'] = labels self.messagelist[uid]['labels'] = labels
self.messagelist[uid]['mtime'] = row[2] self.messagelist[uid]['mtime'] = row[2]
def dropmessagelistcache(self):
self.messagelist = None
# Interface from LocalStatusFolder # Interface from LocalStatusFolder
def save(self): def save(self):
pass pass

View File

@ -220,6 +220,9 @@ class MaildirFolder(BaseFolder):
if self.messagelist is None: if self.messagelist is None:
self.messagelist = self._scanfolder() self.messagelist = self._scanfolder()
def dropmessagelistcache(self):
self.messagelist = None
# Interface from BaseFolder # Interface from BaseFolder
def getmessagelist(self): def getmessagelist(self):
return self.messagelist return self.messagelist

View File

@ -125,6 +125,9 @@ class MappedIMAPFolder(IMAPFolder):
finally: finally:
self.maplock.release() self.maplock.release()
def dropmessagelistcache(self):
self._mb.dropmessagelistcache()
# Interface from BaseFolder # Interface from BaseFolder
def uidexists(self, ruid): def uidexists(self, ruid):
"""Checks if the (remote) UID exists in this Folder""" """Checks if the (remote) UID exists in this Folder"""