[PATCH 6/9] Use self.doautosave rather than self.dofsync

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Apr 26 11:31:37 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 0fd2aaa..6d2cc0a 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 = None
         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)
@@ -125,7 +121,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):
@@ -136,7 +132,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])
@@ -149,4 +145,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 0f85db9..9f7a49d 100644
--- a/offlineimap/folder/LocalStatusSQLite.py
+++ b/offlineimap/folder/LocalStatusSQLite.py
@@ -73,7 +73,7 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
         self.cursor.execute('CREATE TABLE metadata (key VARCHAR(50) PRIMARY KEY, value VARCHAR(128))')
         self.cursor.execute("INSERT INTO metadata VALUES('db_version', '1')")
         self.cursor.execute('CREATE TABLE status (id INTEGER PRIMARY KEY, flags VARCHAR(50))')
-        self.autosave() #commit if needed
+        self.save() #commit if needed
 
     def deletemessagelist(self):
         """delete all messages in the db"""
@@ -125,7 +125,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):
@@ -144,7 +144,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