Revert "Try sqlite3 in-memory fullsync, might be faster"

This reverts commit 0046f34729.
This commit is contained in:
tomkat83 2016-12-03 13:56:53 +01:00
parent 0046f34729
commit 21da5707a0
3 changed files with 8 additions and 48 deletions

View file

@ -12,7 +12,7 @@ import xbmcgui
import artwork import artwork
from utils import tryEncode, tryDecode, settings, window, kodiSQL, \ from utils import tryEncode, tryDecode, settings, window, kodiSQL, \
CatchExceptions, copy_database CatchExceptions
import embydb_functions as embydb import embydb_functions as embydb
import kodidb_functions as kodidb import kodidb_functions as kodidb
@ -33,35 +33,23 @@ class Items(object):
Input: Input:
kodiType: optional argument; e.g. 'video' or 'music' kodiType: optional argument; e.g. 'video' or 'music'
inmemory: Do the work in-memory (copying the Kodi DB around!)
""" """
def __init__(self, inmemory=False): def __init__(self):
self.kodiversion = int(xbmc.getInfoLabel("System.BuildVersion")[:2]) self.kodiversion = int(xbmc.getInfoLabel("System.BuildVersion")[:2])
self.directpath = window('useDirectPaths') == 'true' self.directpath = window('useDirectPaths') == 'true'
self.artwork = artwork.Artwork() self.artwork = artwork.Artwork()
self.userid = window('currUserId') self.userid = window('currUserId')
self.server = window('pms_server') self.server = window('pms_server')
self.inmemory = inmemory
def __enter__(self): def __enter__(self):
""" """
Open DB connections and cursors Open DB connections and cursors
""" """
if self.inmemory is True: self.embyconn = kodiSQL('emby')
# Copy the databases into memory first
log.info('Processing in-memory!')
embyconn = kodiSQL('emby')
self.embyconn = copy_database(embyconn, dest_conn=':memory:')
embyconn.close()
kodiconn = kodiSQL('video')
self.kodiconn = copy_database(kodiconn, dest_conn=':memory:')
kodiconn.close()
else:
self.embyconn = kodiSQL('emby')
self.kodiconn = kodiSQL('video')
self.embycursor = self.embyconn.cursor() self.embycursor = self.embyconn.cursor()
self.kodiconn = kodiSQL('video')
self.kodicursor = self.kodiconn.cursor() self.kodicursor = self.kodiconn.cursor()
self.emby_db = embydb.Embydb_Functions(self.embycursor) self.emby_db = embydb.Embydb_Functions(self.embycursor)
self.kodi_db = kodidb.Kodidb_Functions(self.kodicursor) self.kodi_db = kodidb.Kodidb_Functions(self.kodicursor)
@ -73,15 +61,6 @@ class Items(object):
""" """
self.embyconn.commit() self.embyconn.commit()
self.kodiconn.commit() self.kodiconn.commit()
if self.inmemory is True:
# Copy the in-memory db back to disk
embyconn = kodiSQL('emby')
self.embyconn = copy_database(self.embyconn, embyconn)
embyconn.close()
kodiconn = kodiSQL('video')
self.kodiconn = copy_database(self.kodiconn, kodiconn)
kodiconn.close()
log.info('Processed in-memory finished')
self.embyconn.close() self.embyconn.close()
self.kodiconn.close() self.kodiconn.close()
return self return self

View file

@ -143,13 +143,11 @@ class ThreadedProcessMetadata(Thread):
itemType: as used to call functions in itemtypes.py itemType: as used to call functions in itemtypes.py
e.g. 'Movies' => itemtypes.Movies() e.g. 'Movies' => itemtypes.Movies()
lock: Lock(), used for counting where we are lock: Lock(), used for counting where we are
inmemory: Do the work in-memory (copying the Kodi DB around!)
""" """
def __init__(self, queue, itemType, lock, inmemory=False): def __init__(self, queue, itemType, lock):
self.queue = queue self.queue = queue
self.lock = lock self.lock = lock
self.itemType = itemType self.itemType = itemType
self.inmemory = inmemory
Thread.__init__(self) Thread.__init__(self)
def terminateNow(self): def terminateNow(self):
@ -172,7 +170,7 @@ class ThreadedProcessMetadata(Thread):
threadStopped = self.threadStopped threadStopped = self.threadStopped
global processMetadataCount global processMetadataCount
global processingViewName global processingViewName
with itemFkt(inmemory=self.inmemory) as item: with itemFkt() as item:
while threadStopped() is False: while threadStopped() is False:
# grabs item from queue # grabs item from queue
try: try:
@ -987,17 +985,14 @@ class LibrarySync(Thread):
thread.start() thread.start()
threads.append(thread) threads.append(thread)
log.info("%s download threads spawned" % len(threads)) log.info("%s download threads spawned" % len(threads))
# Process the Kodi DB in-memory if we got a lot of items
inmemory = True if itemNumber > 50 else False
# Spawn one more thread to process Metadata, once downloaded # Spawn one more thread to process Metadata, once downloaded
thread = ThreadedProcessMetadata(processMetadataQueue, thread = ThreadedProcessMetadata(processMetadataQueue,
itemType, itemType,
processMetadataLock, processMetadataLock)
inmemory=inmemory)
thread.setDaemon(True) thread.setDaemon(True)
thread.start() thread.start()
threads.append(thread) threads.append(thread)
log.info("Processing thread spawned with inmemory=%s" % inmemory) log.info("Processing thread spawned")
# Start one thread to show sync progress ONLY for new PMS items # Start one thread to show sync progress ONLY for new PMS items
if self.new_items_only is True and window('dbSyncIndicator') == 'true': if self.new_items_only is True and window('dbSyncIndicator') == 'true':
dialog = xbmcgui.DialogProgressBG() dialog = xbmcgui.DialogProgressBG()

View file

@ -212,20 +212,6 @@ def kodiSQL(media_type="video"):
connection = sqlite3.connect(dbPath, timeout=15.0) connection = sqlite3.connect(dbPath, timeout=15.0)
return connection return connection
def copy_database(source_conn, dest_conn=':memory:'):
'''
Returns a connection to a new copy of an existing database. Raises an
sqlite3.OperationalError if the destination already exists.
dest_conn=':memory:' causes the destination db to reside in-memory
'''
if dest_conn == ':memory:':
dest_conn = sqlite3.connect(dest_conn, timeout=15.0)
dest_conn.executescript(''.join(source_conn.iterdump()))
return dest_conn
def getKodiVideoDBPath(): def getKodiVideoDBPath():
dbVersion = { dbVersion = {