Optimize DB access for ratings and unique id
This commit is contained in:
parent
5f7426da1c
commit
b6fc820f81
2 changed files with 17 additions and 17 deletions
|
@ -360,7 +360,8 @@ class Movies(Items):
|
|||
LOG.info("ADD movie itemid: %s - Title: %s", itemid, title)
|
||||
if v.KODIVERSION >= 17:
|
||||
# add new ratings Kodi 17
|
||||
rating_id = self.kodi_db.create_entry_rating()
|
||||
rating_id = self.kodi_db.get_ratingid(movieid,
|
||||
v.KODI_TYPE_MOVIE)
|
||||
self.kodi_db.add_ratings(rating_id,
|
||||
movieid,
|
||||
v.KODI_TYPE_MOVIE,
|
||||
|
@ -369,7 +370,8 @@ class Movies(Items):
|
|||
votecount)
|
||||
# add new uniqueid Kodi 17
|
||||
if imdb is not None:
|
||||
uniqueid = self.kodi_db.create_entry_uniqueid()
|
||||
uniqueid = self.kodi_db.get_uniqueid(movieid,
|
||||
v.KODI_TYPE_MOVIE)
|
||||
self.kodi_db.add_uniqueid(uniqueid,
|
||||
movieid,
|
||||
v.KODI_TYPE_MOVIE,
|
||||
|
@ -687,7 +689,7 @@ class TVShows(Items):
|
|||
view_id=viewid)
|
||||
if v.KODIVERSION >= 17:
|
||||
# add new ratings Kodi 17
|
||||
rating_id = self.kodi_db.create_entry_rating()
|
||||
rating_id = self.kodi_db.get_ratingid(showid, v.KODI_TYPE_SHOW)
|
||||
self.kodi_db.add_ratings(rating_id,
|
||||
showid,
|
||||
v.KODI_TYPE_SHOW,
|
||||
|
@ -696,7 +698,8 @@ class TVShows(Items):
|
|||
votecount)
|
||||
# add new uniqueid Kodi 17
|
||||
if tvdb is not None:
|
||||
uniqueid = self.kodi_db.create_entry_uniqueid()
|
||||
uniqueid = self.kodi_db.get_uniqueid(showid,
|
||||
v.KODI_TYPE_SHOW)
|
||||
self.kodi_db.add_uniqueid(uniqueid,
|
||||
showid,
|
||||
v.KODI_TYPE_SHOW,
|
||||
|
@ -995,7 +998,8 @@ class TVShows(Items):
|
|||
# Create the episode entry
|
||||
if v.KODIVERSION >= 17:
|
||||
# add new ratings Kodi 17
|
||||
rating_id = self.kodi_db.create_entry_rating()
|
||||
rating_id = self.kodi_db.get_ratingid(episodeid,
|
||||
v.KODI_TYPE_EPISODE)
|
||||
self.kodi_db.add_ratings(rating_id,
|
||||
episodeid,
|
||||
v.KODI_TYPE_EPISODE,
|
||||
|
@ -1003,7 +1007,9 @@ class TVShows(Items):
|
|||
rating,
|
||||
votecount)
|
||||
# add new uniqueid Kodi 17
|
||||
self.kodi_db.add_uniqueid(self.kodi_db.create_entry_uniqueid(),
|
||||
uniqueid = self.kodi_db.get_uniqueid(episodeid,
|
||||
v.KODI_TYPE_EPISODE)
|
||||
self.kodi_db.add_uniqueid(uniqueid,
|
||||
episodeid,
|
||||
v.KODI_TYPE_EPISODE,
|
||||
tvdb,
|
||||
|
|
|
@ -1197,11 +1197,6 @@ class KodiDBMethods(object):
|
|||
query = '''UPDATE %s SET userrating = ? WHERE ? = ?''' % kodi_type
|
||||
self.cursor.execute(query, (userrating, ID, kodi_id))
|
||||
|
||||
def create_entry_uniqueid(self):
|
||||
self.cursor.execute(
|
||||
"select coalesce(max(uniqueid_id),0) from uniqueid")
|
||||
return self.cursor.fetchone()[0] + 1
|
||||
|
||||
def add_uniqueid(self, *args):
|
||||
"""
|
||||
Feed with:
|
||||
|
@ -1227,7 +1222,9 @@ class KodiDBMethods(object):
|
|||
try:
|
||||
uniqueid = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
uniqueid = None
|
||||
self.cursor.execute(
|
||||
'SELECT COALESCE(MAX(uniqueid_id),0) FROM uniqueid')
|
||||
uniqueid = self.cursor.fetchone()[0] + 1
|
||||
return uniqueid
|
||||
|
||||
def update_uniqueid(self, *args):
|
||||
|
@ -1248,10 +1245,6 @@ class KodiDBMethods(object):
|
|||
'''
|
||||
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||
|
||||
def create_entry_rating(self):
|
||||
self.cursor.execute("select coalesce(max(rating_id),0) from rating")
|
||||
return self.cursor.fetchone()[0] + 1
|
||||
|
||||
def get_ratingid(self, kodi_id, kodi_type):
|
||||
query = '''
|
||||
SELECT rating_id FROM rating
|
||||
|
@ -1261,7 +1254,8 @@ class KodiDBMethods(object):
|
|||
try:
|
||||
ratingid = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
ratingid = None
|
||||
self.cursor.execute('SELECT COALESCE(MAX(rating_id),0) FROM rating')
|
||||
ratingid = self.cursor.fetchone()[0] + 1
|
||||
return ratingid
|
||||
|
||||
def update_ratings(self, *args):
|
||||
|
|
Loading…
Reference in a new issue