Rework people sync to avoid exception program flow

This commit is contained in:
Matt 2021-03-13 20:13:40 -05:00
parent a78ab1377c
commit 2d60480df3

View file

@ -163,18 +163,19 @@ class Kodi(object):
return self.cursor.lastrowid return self.cursor.lastrowid
def _get_person(self, *args): def _get_person(self, *args):
try: '''Retrieve person from the database, or add them if they don't exist
'''
resp = self.cursor.execute(QU.get_person, args).fetchone()
if len(resp) > 0:
return resp[0]
else:
return self.add_person(*args) return self.add_person(*args)
except IntegrityError:
# The person already exists in the database
# Now we can do the expensive operation of fetching the id
self.cursor.execute(QU.get_person, args)
return self.cursor.fetchone()[0]
def get_person(self, *args): def get_person(self, *args):
try: '''Retrieve person from cache, else forward to db query
return self._people_cache[args] '''
except KeyError: person_id = self._people_cache.get(args)
if not person_id:
person_id = self._get_person(*args) person_id = self._get_person(*args)
self._people_cache[args] = person_id self._people_cache[args] = person_id
return person_id return person_id