Always use sqlite WAL mode (did not switch back to normal journal mode automatically anyway)
This commit is contained in:
parent
d4d7c0f98c
commit
3000bfcd7d
3 changed files with 12 additions and 20 deletions
|
@ -52,26 +52,21 @@ def catch_operationalerrors(method):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def _initial_db_connection_setup(conn, wal_mode):
|
def _initial_db_connection_setup(conn):
|
||||||
"""
|
"""
|
||||||
Set-up DB e.g. for WAL journal mode, if that hasn't already been done
|
Set-up DB e.g. for WAL journal mode, if that hasn't already been done
|
||||||
before. Also start a transaction
|
before. Also start a transaction
|
||||||
"""
|
"""
|
||||||
if wal_mode:
|
conn.execute('PRAGMA journal_mode = WAL;')
|
||||||
pass
|
conn.execute('PRAGMA cache_size = -8000;')
|
||||||
# conn.execute('PRAGMA journal_mode=WAL;')
|
conn.execute('PRAGMA synchronous = NORMAL;')
|
||||||
# conn.execute('PRAGMA cache_size = -8000;')
|
|
||||||
# conn.execute('PRAGMA synchronous=NORMAL;')
|
|
||||||
conn.execute('BEGIN')
|
conn.execute('BEGIN')
|
||||||
|
|
||||||
|
|
||||||
def connect(media_type=None, wal_mode=True):
|
def connect(media_type=None):
|
||||||
"""
|
"""
|
||||||
Open a connection to the Kodi database.
|
Open a connection to the Kodi database.
|
||||||
media_type: 'video' (standard if not passed), 'plex', 'music', 'texture'
|
media_type: 'video' (standard if not passed), 'plex', 'music', 'texture'
|
||||||
Pass wal_mode=False if you want the standard (and slower) sqlite
|
|
||||||
journal_mode, e.g. when wiping entire tables. Useful if you do NOT want
|
|
||||||
concurrent access to DB for both PKC and Kodi
|
|
||||||
"""
|
"""
|
||||||
if media_type == "plex":
|
if media_type == "plex":
|
||||||
db_path = v.DB_PLEX_PATH
|
db_path = v.DB_PLEX_PATH
|
||||||
|
@ -87,7 +82,7 @@ def connect(media_type=None, wal_mode=True):
|
||||||
attempts = DB_WRITE_ATTEMPTS
|
attempts = DB_WRITE_ATTEMPTS
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
_initial_db_connection_setup(conn, wal_mode)
|
_initial_db_connection_setup(conn)
|
||||||
except sqlite3.OperationalError as err:
|
except sqlite3.OperationalError as err:
|
||||||
if 'database is locked' not in err:
|
if 'database is locked' not in err:
|
||||||
# Not an error we want to catch, so reraise it
|
# Not an error we want to catch, so reraise it
|
||||||
|
|
|
@ -62,7 +62,7 @@ def setup_kodi_default_entries():
|
||||||
def reset_cached_images():
|
def reset_cached_images():
|
||||||
LOG.info('Resetting cached artwork')
|
LOG.info('Resetting cached artwork')
|
||||||
LOG.debug('Resetting the Kodi texture DB')
|
LOG.debug('Resetting the Kodi texture DB')
|
||||||
with KodiTextureDB(wal_mode=False) as kodidb:
|
with KodiTextureDB() as kodidb:
|
||||||
kodidb.wipe()
|
kodidb.wipe()
|
||||||
LOG.debug('Deleting all cached image files')
|
LOG.debug('Deleting all cached image files')
|
||||||
path = path_ops.translate_path('special://thumbnails/')
|
path = path_ops.translate_path('special://thumbnails/')
|
||||||
|
@ -91,11 +91,11 @@ def wipe_dbs(music=True):
|
||||||
"""
|
"""
|
||||||
LOG.warn('Wiping Kodi databases!')
|
LOG.warn('Wiping Kodi databases!')
|
||||||
LOG.info('Wiping Kodi video database')
|
LOG.info('Wiping Kodi video database')
|
||||||
with KodiVideoDB(wal_mode=False) as kodidb:
|
with KodiVideoDB() as kodidb:
|
||||||
kodidb.wipe()
|
kodidb.wipe()
|
||||||
if music:
|
if music:
|
||||||
LOG.info('Wiping Kodi music database')
|
LOG.info('Wiping Kodi music database')
|
||||||
with KodiMusicDB(wal_mode=False) as kodidb:
|
with KodiMusicDB() as kodidb:
|
||||||
kodidb.wipe()
|
kodidb.wipe()
|
||||||
reset_cached_images()
|
reset_cached_images()
|
||||||
setup_kodi_default_entries()
|
setup_kodi_default_entries()
|
||||||
|
|
|
@ -15,11 +15,9 @@ class KodiDBBase(object):
|
||||||
Kodi database methods used for all types of items
|
Kodi database methods used for all types of items
|
||||||
"""
|
"""
|
||||||
def __init__(self, texture_db=False, kodiconn=None, artconn=None,
|
def __init__(self, texture_db=False, kodiconn=None, artconn=None,
|
||||||
lock=True, wal_mode=True):
|
lock=True):
|
||||||
"""
|
"""
|
||||||
Allows direct use with a cursor instead of context mgr
|
Allows direct use with a cursor instead of context mgr
|
||||||
Pass wal_mode=False if you want the standard sqlite journal_mode, e.g.
|
|
||||||
when wiping entire tables
|
|
||||||
"""
|
"""
|
||||||
self._texture_db = texture_db
|
self._texture_db = texture_db
|
||||||
self.lock = lock
|
self.lock = lock
|
||||||
|
@ -27,14 +25,13 @@ class KodiDBBase(object):
|
||||||
self.cursor = self.kodiconn.cursor() if self.kodiconn else None
|
self.cursor = self.kodiconn.cursor() if self.kodiconn else None
|
||||||
self.artconn = artconn
|
self.artconn = artconn
|
||||||
self.artcursor = self.artconn.cursor() if self.artconn else None
|
self.artcursor = self.artconn.cursor() if self.artconn else None
|
||||||
self.wal_mode = wal_mode
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
if self.lock:
|
if self.lock:
|
||||||
KODIDB_LOCK.acquire()
|
KODIDB_LOCK.acquire()
|
||||||
self.kodiconn = db.connect(self.db_kind, self.wal_mode)
|
self.kodiconn = db.connect(self.db_kind)
|
||||||
self.cursor = self.kodiconn.cursor()
|
self.cursor = self.kodiconn.cursor()
|
||||||
self.artconn = db.connect('texture', self.wal_mode) if self._texture_db \
|
self.artconn = db.connect('texture') if self._texture_db \
|
||||||
else None
|
else None
|
||||||
self.artcursor = self.artconn.cursor() if self._texture_db else None
|
self.artcursor = self.artconn.cursor() if self._texture_db else None
|
||||||
return self
|
return self
|
||||||
|
|
Loading…
Reference in a new issue