From 6de47490c314acc0e8b26b3de6432cf2d63de44c Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 10 Nov 2018 16:18:22 +0100 Subject: [PATCH] Revert "Wrap Kodi DB transactions explicitly" This reverts commit be45d914d32682163c9965aae38bcb8a483f9bdf. --- resources/lib/itemtypes/common.py | 18 +++++------------- resources/lib/library_sync/process_metadata.py | 8 ++++---- resources/lib/utils.py | 11 +++-------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/resources/lib/itemtypes/common.py b/resources/lib/itemtypes/common.py index fcf09e4d..d368c1fd 100644 --- a/resources/lib/itemtypes/common.py +++ b/resources/lib/itemtypes/common.py @@ -56,11 +56,10 @@ class ItemBase(object): """ self.plexconn = utils.kodi_sql('plex') self.plexcursor = self.plexconn.cursor() + self.kodiconn = utils.kodi_sql('video') + self.kodicursor = self.kodiconn.cursor() self.artconn = utils.kodi_sql('texture') self.artcursor = self.artconn.cursor() - self.kodiconn = utils.kodi_sql('video', writer=True) - self.kodicursor = self.kodiconn.cursor() - self.kodicursor.execute('BEGIN') self.plexdb = PlexDB(self.plexcursor) self.kodidb = KodiVideoDB(texture_db=True, cursor=self.kodicursor, @@ -72,20 +71,13 @@ class ItemBase(object): Make sure DB changes are committed and connection to DB is closed. """ self.plexconn.commit() + self.kodiconn.commit() + self.artconn.commit() self.plexconn.close() - self.artconn.commit() - self.artconn.close() - self.kodicursor.execute('END TRANSACTION') self.kodiconn.close() + self.artconn.close() return self - def commit(self): - self.plexconn.commit() - self.artconn.commit() - self.kodicursor.execute('END TRANSACTION') - self.kodicursor.execute('PRAGMA wal_checkpoint(FULL);') - self.kodicursor.execute('BEGIN TRANSACTION') - def set_fanart(self, artworks, kodi_id, kodi_type): """ Writes artworks [dict containing only set artworks] to the Kodi art DB diff --git a/resources/lib/library_sync/process_metadata.py b/resources/lib/library_sync/process_metadata.py index fe061265..54fd8632 100644 --- a/resources/lib/library_sync/process_metadata.py +++ b/resources/lib/library_sync/process_metadata.py @@ -123,12 +123,12 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin): self.processed += 1 self.update_progressbar() self.current += 1 - if self.processed == 200: + if self.processed == 500: self.processed = 0 - context.commit() + context.kodiconn.commit() + context.artconn.commit() + context.plexconn.commit() self.queue.task_done() - if section.plex_type == 'episode' and self.current == 1000: - break profile.disable() string_io = StringIO() stats = Stats(profile, stream=string_io).sort_stats('cumulative') diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 99284cf6..56c1c102 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -475,7 +475,7 @@ def unix_timestamp(seconds_into_the_future=None): return int((future - EPOCH).total_seconds()) -def kodi_sql(media_type=None, writer=False): +def kodi_sql(media_type=None): """ Open a connection to the Kodi database. media_type: 'video' (standard if not passed), 'plex', 'music', 'texture' @@ -488,13 +488,8 @@ def kodi_sql(media_type=None, writer=False): db_path = v.DB_TEXTURE_PATH else: db_path = v.DB_VIDEO_PATH - if writer: - conn = connect(db_path, timeout=5.0, isolation_level=None) - conn.execute('PRAGMA journal_mode=WAL') - # conn.execute('BEGIN TRANSACTION') - else: - conn = connect(db_path, timeout=5.0) - conn.execute('PRAGMA journal_mode=WAL') + conn = connect(db_path, timeout=5.0) + conn.execute('PRAGMA journal_mode=WAL') return conn