mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-11-10 18:36:33 +00:00
Bulk operations where possible.
Avoiding many individual DB API calls to cursor.execute in favour of cursor.executemany is a built in optimization for many SQL databases. When updating people we are adding lots of similar data to tables so we can take advantage of that optimization here.
This commit is contained in:
parent
4a4318c1ed
commit
0b7d66b551
1 changed files with 13 additions and 8 deletions
|
|
@ -127,31 +127,36 @@ class Kodi(object):
|
||||||
|
|
||||||
self.artwork.update(person['imageurl'], person_id, art, "thumb")
|
self.artwork.update(person['imageurl'], person_id, art, "thumb")
|
||||||
|
|
||||||
def add_link(link, person_id):
|
|
||||||
self.cursor.execute(QU.update_link.replace("{LinkType}", link), (person_id,) + args)
|
|
||||||
|
|
||||||
cast_order = 1
|
cast_order = 1
|
||||||
|
|
||||||
|
bulk_updates = {}
|
||||||
|
|
||||||
for person in people:
|
for person in people:
|
||||||
person_id = self.get_person(person['Name'])
|
person_id = self.get_person(person['Name'])
|
||||||
|
|
||||||
if person['Type'] == 'Actor':
|
if person['Type'] == 'Actor':
|
||||||
|
sql = QU.update_actor
|
||||||
role = person.get('Role')
|
role = person.get('Role')
|
||||||
self.cursor.execute(QU.update_actor, (person_id,) + args + (role, cast_order,))
|
bulk_updates.setdefault(sql, []).append((person_id,) + args + (role, cast_order,))
|
||||||
cast_order += 1
|
cast_order += 1
|
||||||
|
|
||||||
elif person['Type'] == 'Director':
|
elif person['Type'] == 'Director':
|
||||||
add_link('director_link', person_id)
|
sql = QU.update_link.replace("{LinkType}", 'director_link')
|
||||||
|
bulk_updates.setdefault(sql, []).append((person_id,) + args)
|
||||||
|
|
||||||
elif person['Type'] == 'Writer':
|
elif person['Type'] == 'Writer':
|
||||||
add_link('writer_link', person_id)
|
sql = QU.update_link.replace("{LinkType}", 'writer_link')
|
||||||
|
bulk_updates.setdefault(sql, []).append((person_id,) + args)
|
||||||
|
|
||||||
elif person['Type'] == 'Artist':
|
elif person['Type'] == 'Artist':
|
||||||
add_link('actor_link', person_id)
|
sql = QU.update_link.replace("{LinkType}", 'actor_link')
|
||||||
|
bulk_updates.setdefault(sql, []).append((person_id,) + args)
|
||||||
|
|
||||||
add_thumbnail(person_id, person, person['Type'])
|
add_thumbnail(person_id, person, person['Type'])
|
||||||
|
|
||||||
|
for sql, parameters in bulk_updates.items():
|
||||||
|
self.cursor.executemany(sql, parameters)
|
||||||
|
|
||||||
def add_person(self, *args):
|
def add_person(self, *args):
|
||||||
|
|
||||||
person_id = self.create_entry_person()
|
person_id = self.create_entry_person()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue