From e1e9c8e831b9ee46a572340033b9c861962a19d0 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 5 May 2011 15:59:26 +0200 Subject: [PATCH] Use self.doautosave rather than self.dofsync 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 Signed-off-by: Nicolas Sebrecht --- 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 467738d..5113345 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__() @@ -88,10 +88,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: @@ -103,12 +99,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) @@ -129,7 +125,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): @@ -140,7 +136,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]) @@ -153,4 +149,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