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 <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
bd3766eca5
commit
e1e9c8e831
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user