Added local cache of people

Prevent any access to the people database unless a person must be added.
This commit is contained in:
Chuddah 2020-02-18 20:37:26 +00:00
commit 4a4318c1ed
2 changed files with 16 additions and 1 deletions

View file

@ -22,6 +22,9 @@ class Kodi(object):
def __init__(self):
self.artwork = artwork.Artwork(self.cursor)
self.cursor.execute(QU.get_all_people)
self._people_cache = dict(self.cursor.fetchall())
def create_entry_path(self):
self.cursor.execute(QU.create_path)
@ -156,7 +159,7 @@ class Kodi(object):
return person_id
def get_person(self, *args):
def _get_person(self, *args):
try:
return self.add_person(*args)
except IntegrityError:
@ -165,6 +168,14 @@ class Kodi(object):
self.cursor.execute(QU.get_person, args)
return self.cursor.fetchone()[0]
def get_person(self, *args):
try:
return self._people_cache[args]
except KeyError:
person_id = self._get_person(*args)
self._people_cache[args] = person_id
return person_id
def add_genres(self, genres, *args):
''' Delete current genres first for clean slate.

View file

@ -88,6 +88,10 @@ SELECT strFilename
FROM files
WHERE idFile = ?
"""
get_all_people = """
SELECT name, actor_id
FROM actor
"""
get_person = """
SELECT actor_id
FROM actor