From f02bb4a8731ba6e04960911165f09e436b14fd7b Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 4 Dec 2016 12:26:25 +0100 Subject: [PATCH] Index Kodi database actor names to speed up sync --- resources/lib/librarysync.py | 5 ++++- resources/lib/utils.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 30585170..ee1e8055 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -15,7 +15,7 @@ from utils import window, settings, getUnixTimestamp, kodiSQL, sourcesXML,\ ThreadMethods, ThreadMethodsAdditionalStop, LogTime, getScreensaver,\ setScreensaver, playlistXSP, language as lang, DateToKodi, reset,\ advancedSettingsXML, getKodiVideoDBPath, tryDecode, deletePlaylists,\ - deleteNodes, ThreadMethodsAdditionalSuspend + deleteNodes, ThreadMethodsAdditionalSuspend, create_actor_db_index import clientinfo import downloadutils import itemtypes @@ -558,6 +558,9 @@ class LibrarySync(Thread): # content sync: movies, tvshows, musicvideos, music embyconn.close() + # Create an index for actors to speed up sync + create_actor_db_index() + @LogTime def fullSync(self, repair=False): """ diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 6394dc35..132d9c51 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -229,6 +229,25 @@ def getKodiVideoDBPath(): % dbVersion.get(xbmc.getInfoLabel('System.BuildVersion')[:2], ""))) return dbPath + +def create_actor_db_index(): + """ + Index the "actors" because we got a TON - speed up SELECT and WHEN + """ + conn = kodiSQL('video') + cursor = conn.cursor() + try: + cursor.execute(""" + CREATE UNIQUE INDEX index_name + ON actor (name); + """) + except sqlite3.OperationalError: + # Index already exists + pass + conn.commit() + conn.close() + + def getKodiMusicDBPath(): dbVersion = {