Optimize DB access for ratings and unique id

This commit is contained in:
croneter 2018-02-26 10:58:27 +01:00
parent 5f7426da1c
commit b6fc820f81
2 changed files with 17 additions and 17 deletions

View file

@ -360,7 +360,8 @@ class Movies(Items):
LOG.info("ADD movie itemid: %s - Title: %s", itemid, title) LOG.info("ADD movie itemid: %s - Title: %s", itemid, title)
if v.KODIVERSION >= 17: if v.KODIVERSION >= 17:
# add new ratings Kodi 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, self.kodi_db.add_ratings(rating_id,
movieid, movieid,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
@ -369,7 +370,8 @@ class Movies(Items):
votecount) votecount)
# add new uniqueid Kodi 17 # add new uniqueid Kodi 17
if imdb is not None: 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, self.kodi_db.add_uniqueid(uniqueid,
movieid, movieid,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
@ -687,7 +689,7 @@ class TVShows(Items):
view_id=viewid) view_id=viewid)
if v.KODIVERSION >= 17: if v.KODIVERSION >= 17:
# add new ratings Kodi 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, self.kodi_db.add_ratings(rating_id,
showid, showid,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
@ -696,7 +698,8 @@ class TVShows(Items):
votecount) votecount)
# add new uniqueid Kodi 17 # add new uniqueid Kodi 17
if tvdb is not None: 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, self.kodi_db.add_uniqueid(uniqueid,
showid, showid,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
@ -995,7 +998,8 @@ class TVShows(Items):
# Create the episode entry # Create the episode entry
if v.KODIVERSION >= 17: if v.KODIVERSION >= 17:
# add new ratings Kodi 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, self.kodi_db.add_ratings(rating_id,
episodeid, episodeid,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
@ -1003,7 +1007,9 @@ class TVShows(Items):
rating, rating,
votecount) votecount)
# add new uniqueid Kodi 17 # 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, episodeid,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
tvdb, tvdb,

View file

@ -1197,11 +1197,6 @@ class KodiDBMethods(object):
query = '''UPDATE %s SET userrating = ? WHERE ? = ?''' % kodi_type query = '''UPDATE %s SET userrating = ? WHERE ? = ?''' % kodi_type
self.cursor.execute(query, (userrating, ID, kodi_id)) 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): def add_uniqueid(self, *args):
""" """
Feed with: Feed with:
@ -1227,7 +1222,9 @@ class KodiDBMethods(object):
try: try:
uniqueid = self.cursor.fetchone()[0] uniqueid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
uniqueid = None self.cursor.execute(
'SELECT COALESCE(MAX(uniqueid_id),0) FROM uniqueid')
uniqueid = self.cursor.fetchone()[0] + 1
return uniqueid return uniqueid
def update_uniqueid(self, *args): def update_uniqueid(self, *args):
@ -1248,10 +1245,6 @@ class KodiDBMethods(object):
''' '''
self.cursor.execute(query, (kodi_id, kodi_type)) 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): def get_ratingid(self, kodi_id, kodi_type):
query = ''' query = '''
SELECT rating_id FROM rating SELECT rating_id FROM rating
@ -1261,7 +1254,8 @@ class KodiDBMethods(object):
try: try:
ratingid = self.cursor.fetchone()[0] ratingid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
ratingid = None self.cursor.execute('SELECT COALESCE(MAX(rating_id),0) FROM rating')
ratingid = self.cursor.fetchone()[0] + 1
return ratingid return ratingid
def update_ratings(self, *args): def update_ratings(self, *args):