[PATCHv5 4/7] Use self.doautosave rather than self.dofsync

Sebastian Spaeth Sebastian at SSpaeth.de
Thu May 5 14:59:26 BST 2011


doautosave was a useless variable before (it was *always* 1). So we
remove the self.dofsync variable and store in doautosave whether we
should fsync as often as possible (which really hurts performance).

The sqlite backend could (at one point) use the doautosave variable to
determine if it should autocommit after each modification.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/LocalStatus.py       |   18 +++++++-----------
 offlineimap/folder/LocalStatusSQLite.py |    6 +++---
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py
index 5d96c86..f10e7c2 100644
--- a/offlineimap/folder/LocalStatus.py
+++ b/offlineimap/folder/LocalStatus.py
@@ -28,12 +28,12 @@ class LocalStatusFolder(BaseFolder):
         self.root = root
         self.sep = '.'
         self.config = config
-        self.dofsync = config.getdefaultboolean("general", "fsync", True)
         self.filename = repository.getfolderfilename(name)
         self.messagelist = {}
         self.repository = repository
         self.savelock = threading.Lock()
-        self.doautosave = 1
+        self.doautosave = config.getdefaultboolean("general", "fsync", False)
+        """Should we perform fsyncs as often as possible?"""
         self.accountname = accountname
         super(LocalStatusFolder, self).__init__()
 
@@ -83,10 +83,6 @@ class LocalStatusFolder(BaseFolder):
             self.messagelist[uid] = {'uid': uid, 'flags': flags}
         file.close()
 
-    def autosave(self):
-        if self.doautosave:
-            self.save()
-
     def save(self):
         self.savelock.acquire()
         try:
@@ -98,12 +94,12 @@ class LocalStatusFolder(BaseFolder):
                 flags = ''.join(flags)
                 file.write("%s:%s\n" % (msg['uid'], flags))
             file.flush()
-            if self.dofsync:
+            if self.doautosave:
                 os.fsync(file.fileno())
             file.close()
             os.rename(self.filename + ".tmp", self.filename)
 
-            if self.dofsync:
+            if self.doautosave:
                 fd = os.open(os.path.dirname(self.filename), os.O_RDONLY)
                 os.fsync(fd)
                 os.close(fd)
@@ -124,7 +120,7 @@ class LocalStatusFolder(BaseFolder):
             return uid
 
         self.messagelist[uid] = {'uid': uid, 'flags': flags, 'time': rtime}
-        self.autosave()
+        self.save()
         return uid
 
     def getmessageflags(self, uid):
@@ -135,7 +131,7 @@ class LocalStatusFolder(BaseFolder):
 
     def savemessageflags(self, uid, flags):
         self.messagelist[uid]['flags'] = flags
-        self.autosave()
+        self.save()
 
     def deletemessage(self, uid):
         self.deletemessages([uid])
@@ -148,4 +144,4 @@ class LocalStatusFolder(BaseFolder):
 
         for uid in uidlist:
             del(self.messagelist[uid])
-        self.autosave()
+        self.save()
diff --git a/offlineimap/folder/LocalStatusSQLite.py b/offlineimap/folder/LocalStatusSQLite.py
index 701592c..c8c179f 100644
--- a/offlineimap/folder/LocalStatusSQLite.py
+++ b/offlineimap/folder/LocalStatusSQLite.py
@@ -103,7 +103,7 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
         cursor.execute('CREATE TABLE metadata (key VARCHAR(50) PRIMARY KEY, value VARCHAR(128))')
         cursor.execute("INSERT INTO metadata VALUES('db_version', '1')")
         cursor.execute('CREATE TABLE status (id INTEGER PRIMARY KEY, flags VARCHAR(50))')
-        self.autosave() #commit if needed
+        self.save() #commit if needed
 
     def isnewfolder(self):
         # testing the existence of the db file won't work. It is created
@@ -159,7 +159,7 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
         flags = ''.join(flags)
         self.cursor.execute('INSERT INTO status (id,flags) VALUES (?,?)',
                             (uid,flags))
-        self.autosave()
+        self.save()
         return uid
 
     def getmessageflags(self, uid):
@@ -178,7 +178,7 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
         flags.sort()
         flags = ''.join(flags)
         self.cursor.execute('UPDATE status SET flags=? WHERE id=?',(flags,uid))
-        self.autosave()
+        self.save()
 
     def deletemessages(self, uidlist):
         # Weed out ones not in self.messagelist
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list