From 6fe450da4d9ff9ebcf3fa473b8d56077a2d4c014 Mon Sep 17 00:00:00 2001
From: Chuddah <chuddah@gmail.com>
Date: Sun, 23 Feb 2020 18:27:12 +0000
Subject: [PATCH] Attempt number 2 on a larger dataset; the people table.

Note: This has a previously applied optimization of using a local cache.

Before:
```
458570   66.934    0.000   66.934    0.000 {method 'execute' of 'sqlite3.Cursor' objects}
246771   58.075    0.000   58.075    0.000 {method 'fetchone' of 'sqlite3.Cursor' objects}
```

After:
```
368883   66.220    0.000   66.220    0.000 {method 'execute' of 'sqlite3.Cursor' objects}
157084   58.160    0.000   58.160    0.000 {method 'fetchone' of 'sqlite3.Cursor' objects}
```

Once again, the number of calls to execute and fetchone are reduced but
the total time spent executing each is relatively stable.
---
 jellyfin_kodi/objects/kodi/kodi.py    | 9 ++-------
 jellyfin_kodi/objects/kodi/queries.py | 8 ++------
 2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/jellyfin_kodi/objects/kodi/kodi.py b/jellyfin_kodi/objects/kodi/kodi.py
index dd613089..f1182027 100644
--- a/jellyfin_kodi/objects/kodi/kodi.py
+++ b/jellyfin_kodi/objects/kodi/kodi.py
@@ -40,11 +40,6 @@ class Kodi(object):
 
         return self.cursor.fetchone()[0] + 1
 
-    def create_entry_person(self):
-        self.cursor.execute(QU.create_person)
-
-        return self.cursor.fetchone()[0] + 1
-
     def create_entry_genre(self):
         self.cursor.execute(QU.create_genre)
 
@@ -164,8 +159,8 @@ class Kodi(object):
 
     def add_person(self, *args):
 
-        person_id = self.create_entry_person()
-        self.cursor.execute(QU.add_person, (person_id,) + args)
+        self.cursor.execute(QU.add_person, args)
+        return self.cursor.lastrowid
 
         return person_id
 
diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py
index a9660c8a..e5ca2301 100644
--- a/jellyfin_kodi/objects/kodi/queries.py
+++ b/jellyfin_kodi/objects/kodi/queries.py
@@ -12,10 +12,6 @@ create_file = """
 SELECT      coalesce(max(idFile), 0)
 FROM        files
 """
-create_person = """
-SELECT      coalesce(max(actor_id), 0)
-FROM        actor
-"""
 create_genre = """
 SELECT      coalesce(max(genre_id), 0)
 FROM        genre
@@ -225,8 +221,8 @@ VALUES          (?, ?, ?)
 """
 add_file_obj = ["{PathId}", "{Filename}"]
 add_person = """
-INSERT INTO     actor(actor_id, name)
-VALUES          (?, ?)
+INSERT INTO     actor(name)
+VALUES          (?)
 """
 add_people_movie_obj = ["{People}", "{MovieId}", "movie"]
 add_people_mvideo_obj = ["{People}", "{MvideoId}", "musicvideo"]