Optimize Kodi db method add_season

This commit is contained in:
croneter 2018-03-10 15:02:06 +01:00
parent 54a231a67f
commit f2fea1bcde
2 changed files with 13 additions and 14 deletions

View file

@ -755,7 +755,7 @@ class TVShows(Items):
'Skipping season for now.', plex_id) 'Skipping season for now.', plex_id)
return return
seasonid = self.kodi_db.addSeason(showid, seasonnum) seasonid = self.kodi_db.add_season(showid, seasonnum)
checksum = api.checksum() checksum = api.checksum()
# Check whether Season already exists # Check whether Season already exists
plex_dbitem = plex_db.getItem_byId(plex_id) plex_dbitem = plex_db.getItem_byId(plex_id)
@ -857,7 +857,7 @@ class TVShows(Items):
except TypeError: except TypeError:
LOG.error("Parent tvshow now found, skip item") LOG.error("Parent tvshow now found, skip item")
return False return False
seasonid = self.kodi_db.addSeason(showid, season) seasonid = self.kodi_db.add_season(showid, season)
# GET THE FILE AND PATH ##### # GET THE FILE AND PATH #####
do_indirect = not state.DIRECT_PATHS do_indirect = not state.DIRECT_PATHS

View file

@ -824,24 +824,23 @@ class KodiDBMethods(object):
query = 'DELETE FROM sets WHERE idSet = ?' query = 'DELETE FROM sets WHERE idSet = ?'
self.cursor.execute(query, (set_id,)) self.cursor.execute(query, (set_id,))
def addSeason(self, showid, seasonnumber): def add_season(self, showid, seasonnumber):
"""
query = ' '.join(( Adds a TV show season to the Kodi video DB or simply returns the ID,
if there already is an entry in the DB
"SELECT idSeason", """
"FROM seasons", query = 'SELECT idSeason FROM seasons WHERE idShow = ? AND season = ?'
"WHERE idShow = ?",
"AND season = ?"
))
self.cursor.execute(query, (showid, seasonnumber,)) self.cursor.execute(query, (showid, seasonnumber,))
try: try:
seasonid = self.cursor.fetchone()[0] seasonid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("select coalesce(max(idSeason),0) from seasons") self.cursor.execute("SELECT COALESCE(MAX(idSeason),0) FROM seasons")
seasonid = self.cursor.fetchone()[0] + 1 seasonid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)" query = '''
INSERT INTO seasons(idSeason, idShow, season)
VALUES (?, ?, ?)
'''
self.cursor.execute(query, (seasonid, showid, seasonnumber)) self.cursor.execute(query, (seasonid, showid, seasonnumber))
return seasonid return seasonid
def addArtist(self, name, musicbrainz): def addArtist(self, name, musicbrainz):