mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 12:16:12 +00:00
0a69894320
Profiling has shown that there are many calls to sqlite3.execute and fetchone which takes a signicant amount of time. A simple way of reducing these is to swap the 2-stage init of table row data into a unified add. Applying this to add_set and add_country yielded these results: Before changes ``` 281784 7.054 0.000 7.054 0.000 {method 'execute' of 'sqlite3.Cursor' objects} 127443 1.114 0.000 1.114 0.000 {method 'fetchone' of 'sqlite3.Cursor' objects} ``` After changes ``` 281714 7.492 0.000 7.492 0.000 {method 'execute' of 'sqlite3.Cursor' objects} 127373 1.217 0.000 1.217 0.000 {method 'fetchone' of 'sqlite3.Cursor' objects} ``` Note: The total time of fetchone has actually increased. I am hoping this was an abnormality on my machine and the actual reduction in the number of calls will permantly reduce this total time.
133 lines
3.4 KiB
Python
133 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import division, absolute_import, print_function, unicode_literals
|
|
|
|
##################################################################################################
|
|
|
|
import logging
|
|
|
|
from .kodi import Kodi
|
|
from . import queries as QU
|
|
|
|
##################################################################################################
|
|
|
|
LOG = logging.getLogger("JELLYFIN." + __name__)
|
|
|
|
##################################################################################################
|
|
|
|
|
|
class Movies(Kodi):
|
|
|
|
def __init__(self, cursor):
|
|
|
|
self.cursor = cursor
|
|
Kodi.__init__(self)
|
|
|
|
def create_entry_unique_id(self):
|
|
self.cursor.execute(QU.create_unique_id)
|
|
|
|
return self.cursor.fetchone()[0] + 1
|
|
|
|
def create_entry_rating(self):
|
|
self.cursor.execute(QU.create_rating)
|
|
|
|
return self.cursor.fetchone()[0] + 1
|
|
|
|
def create_entry(self):
|
|
self.cursor.execute(QU.create_movie)
|
|
|
|
return self.cursor.fetchone()[0] + 1
|
|
|
|
def get(self, *args):
|
|
|
|
try:
|
|
self.cursor.execute(QU.get_movie, args)
|
|
return self.cursor.fetchone()[0]
|
|
except TypeError:
|
|
return
|
|
|
|
def add(self, *args):
|
|
self.cursor.execute(QU.add_movie, args)
|
|
|
|
def update(self, *args):
|
|
self.cursor.execute(QU.update_movie, args)
|
|
|
|
def delete(self, kodi_id, file_id):
|
|
|
|
self.cursor.execute(QU.delete_movie, (kodi_id,))
|
|
self.cursor.execute(QU.delete_file, (file_id,))
|
|
|
|
def get_rating_id(self, *args):
|
|
|
|
try:
|
|
self.cursor.execute(QU.get_rating, args)
|
|
|
|
return self.cursor.fetchone()[0]
|
|
except TypeError:
|
|
return None
|
|
|
|
def add_ratings(self, *args):
|
|
|
|
''' Add ratings, rating type and votes.
|
|
'''
|
|
self.cursor.execute(QU.add_rating, args)
|
|
|
|
def update_ratings(self, *args):
|
|
|
|
''' Update rating by rating_id.
|
|
'''
|
|
self.cursor.execute(QU.update_rating, args)
|
|
|
|
def get_unique_id(self, *args):
|
|
|
|
try:
|
|
self.cursor.execute(QU.get_unique_id, args)
|
|
|
|
return self.cursor.fetchone()[0]
|
|
except TypeError:
|
|
return
|
|
|
|
def add_unique_id(self, *args):
|
|
|
|
''' Add the provider id, imdb, tvdb.
|
|
'''
|
|
self.cursor.execute(QU.add_unique_id, args)
|
|
|
|
def update_unique_id(self, *args):
|
|
|
|
''' Update the provider id, imdb, tvdb.
|
|
'''
|
|
self.cursor.execute(QU.update_unique_id, args)
|
|
|
|
def add_countries(self, countries, *args):
|
|
|
|
for country in countries:
|
|
self.cursor.execute(QU.update_country, (self.get_country(country),) + args)
|
|
|
|
def add_country(self, *args):
|
|
self.cursor.execute(QU.add_country, args)
|
|
return self.cursor.lastrowid
|
|
|
|
def get_country(self, *args):
|
|
|
|
try:
|
|
self.cursor.execute(QU.get_country, args)
|
|
|
|
return self.cursor.fetchone()[0]
|
|
except TypeError:
|
|
return self.add_country(*args)
|
|
|
|
def add_boxset(self, *args):
|
|
self.cursor.execute(QU.add_set, args)
|
|
return self.cursor.lastrowid
|
|
|
|
def update_boxset(self, *args):
|
|
self.cursor.execute(QU.update_set, args)
|
|
|
|
def set_boxset(self, *args):
|
|
self.cursor.execute(QU.update_movie_set, args)
|
|
|
|
def remove_from_boxset(self, *args):
|
|
self.cursor.execute(QU.delete_movie_set, args)
|
|
|
|
def delete_boxset(self, *args):
|
|
self.cursor.execute(QU.delete_set, args)
|