mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-11-10 18:36:33 +00:00
Resort to the expensive database lookup only if the person exists in the
database. The database is configured such that each person name within the table has to be unique. Attempting to add a person which already exists causes an IntegrityError exception to be thrown. This is a less costly operation than the cursor.execute and cursor.fetch operations. Increase performance by reverting to the expensive calls of fetching if adding a person fails. This pattern could also be applied to other tables within the database.
This commit is contained in:
parent
b9817a5617
commit
bdd9a8f727
1 changed files with 6 additions and 5 deletions
|
|
@ -8,6 +8,7 @@ import logging
|
|||
from . import artwork
|
||||
from . import queries as QU
|
||||
from helper import values
|
||||
from sqlite3 import IntegrityError
|
||||
|
||||
##################################################################################################
|
||||
|
||||
|
|
@ -156,13 +157,13 @@ class Kodi(object):
|
|||
return person_id
|
||||
|
||||
def get_person(self, *args):
|
||||
|
||||
try:
|
||||
self.cursor.execute(QU.get_person, args)
|
||||
|
||||
return self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
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 add_genres(self, genres, *args):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue