sqlite: open database when we use it rather than at instantiation time
We currently close the database as soon as possible while we handle the status
backend but this is still too early because autorefresh induces looping on this
code block.
Instead of delaying the closing outside of the loop, it's easier to delay the
opening as late as possible (inside the loop). The downside is that the database
is opened/closed more than once when autorefresh is enabled. The good news is
that this make the code much easier.
Fixes regression introduces by 6fb5700
.
Reported-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
14ef992444
commit
05c75e8c8d
@ -513,6 +513,7 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
# Load status folder.
|
# Load status folder.
|
||||||
statusfolder = statusrepos.getfolder(remotefolder.getvisiblename().
|
statusfolder = statusrepos.getfolder(remotefolder.getvisiblename().
|
||||||
replace(remoterepos.getsep(), statusrepos.getsep()))
|
replace(remoterepos.getsep(), statusrepos.getsep()))
|
||||||
|
statusfolder.openfiles()
|
||||||
|
|
||||||
if localfolder.get_uidvalidity() == None:
|
if localfolder.get_uidvalidity() == None:
|
||||||
# This is a new folder, so delete the status cache to be
|
# This is a new folder, so delete the status cache to be
|
||||||
|
@ -154,6 +154,9 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
self.readstatus(cachefd)
|
self.readstatus(cachefd)
|
||||||
cachefd.close()
|
cachefd.close()
|
||||||
|
|
||||||
|
def openfiles(self):
|
||||||
|
pass # Closing files is done on a per-transaction basis.
|
||||||
|
|
||||||
def closefiles(self):
|
def closefiles(self):
|
||||||
pass # Closing files is done on a per-transaction basis.
|
pass # Closing files is done on a per-transaction basis.
|
||||||
|
|
||||||
|
@ -58,9 +58,11 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
raise UserWarning("SQLite database path '%s' is not a directory."%
|
raise UserWarning("SQLite database path '%s' is not a directory."%
|
||||||
dirname)
|
dirname)
|
||||||
|
|
||||||
# dblock protects against concurrent writes in same connection.
|
# This lock protects against concurrent writes in same connection.
|
||||||
self._dblock = Lock()
|
self._dblock = Lock()
|
||||||
|
self.connection = None
|
||||||
|
|
||||||
|
def openfiles(self):
|
||||||
# Try to establish connection, no need for threadsafety in __init__.
|
# Try to establish connection, no need for threadsafety in __init__.
|
||||||
try:
|
try:
|
||||||
self.connection = sqlite.connect(self.filename, check_same_thread=False)
|
self.connection = sqlite.connect(self.filename, check_same_thread=False)
|
||||||
@ -84,10 +86,10 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
cursor = self.connection.execute(
|
cursor = self.connection.execute(
|
||||||
"SELECT value from metadata WHERE key='db_version'")
|
"SELECT value from metadata WHERE key='db_version'")
|
||||||
except sqlite.DatabaseError:
|
except sqlite.DatabaseError:
|
||||||
#db file missing or corrupt, recreate it.
|
# db file missing or corrupt, recreate it.
|
||||||
self.__create_db()
|
self.__create_db()
|
||||||
else:
|
else:
|
||||||
# fetch db version and upgrade if needed
|
# Fetch db version and upgrade if needed.
|
||||||
version = int(cursor.fetchone()[0])
|
version = int(cursor.fetchone()[0])
|
||||||
if version < LocalStatusSQLiteFolder.cur_version:
|
if version < LocalStatusSQLiteFolder.cur_version:
|
||||||
self.__upgrade_db(version)
|
self.__upgrade_db(version)
|
||||||
|
Loading…
Reference in New Issue
Block a user