Skip to content

Commit 9f4ff5d

Browse files
authoredApr 20, 2024
Merge pull request #2061 from Spacetech/db_locks
Reduce database locking
2 parents 6ce769c + 981d36e commit 9f4ff5d

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed
 

‎resources/lib/kodimonitor.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def _get_ids(kodi_id, kodi_type, path):
157157
if not kodi_id and kodi_type and path:
158158
kodi_id, _ = kodi_db.kodiid_from_filename(path, kodi_type)
159159
if kodi_id:
160-
with PlexDB() as plexdb:
160+
with PlexDB(lock=False) as plexdb:
161161
db_item = plexdb.item_by_kodi_id(kodi_id, kodi_type)
162162
if db_item:
163163
plex_id = db_item['plex_id']
@@ -419,7 +419,7 @@ def _record_playstate(status, ended):
419419
if status['plex_type'] not in v.PLEX_VIDEOTYPES:
420420
LOG.debug('Not messing with non-video entries')
421421
return
422-
with PlexDB() as plexdb:
422+
with PlexDB(lock=False) as plexdb:
423423
db_item = plexdb.item_by_id(status['plex_id'], status['plex_type'])
424424
if not db_item:
425425
# Item not (yet) in Kodi library
@@ -466,7 +466,7 @@ def _playback_progress(status, ended, db_item):
466466
playcount = status['playcount']
467467
if playcount is None:
468468
LOG.debug('playcount not found, looking it up in the Kodi DB')
469-
with kodi_db.KodiVideoDB() as kodidb:
469+
with kodi_db.KodiVideoDB(lock=False) as kodidb:
470470
playcount = kodidb.get_playcount(db_item['kodi_fileid']) or 0
471471
if status['external_player']:
472472
# video has either been entirely watched - or not.
@@ -535,7 +535,7 @@ def _external_player_correct_plex_watch_count(db_item):
535535
playcountminimumtime set in playercorefactory.xml)
536536
See https://kodi.wiki/view/External_players
537537
"""
538-
with kodi_db.KodiVideoDB() as kodidb:
538+
with kodi_db.KodiVideoDB(lock=False) as kodidb:
539539
playcount = kodidb.get_playcount(db_item['kodi_fileid'])
540540
LOG.debug('External player detected. Playcount: %s', playcount)
541541
PF.scrobble(db_item['plex_id'], 'watched' if playcount else 'unwatched')

‎resources/lib/library_sync/additional_metadata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def should_suspend(self):
4343
def _process_in_batches(self, item_getter, processor, plex_type):
4444
offset = 0
4545
while True:
46-
with PlexDB() as plexdb:
46+
with PlexDB(lock=False) as plexdb:
4747
# Keep DB connection open only for a short period of time!
4848
if self.refresh:
4949
# Simply grab every single item if we want to refresh

‎resources/lib/library_sync/additional_metadata_tmdb.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def get_tmdb_details(unique_ids):
4848
def process_trailers(plex_id, plex_type, refresh=False):
4949
done = True
5050
try:
51-
with PlexDB() as plexdb:
51+
with PlexDB(lock=False) as plexdb:
5252
db_item = plexdb.item_by_id(plex_id, plex_type)
5353
if not db_item:
5454
logger.error('Could not get Kodi id for %s %s', plex_type, plex_id)
5555
done = False
5656
return
57-
with KodiVideoDB() as kodidb:
57+
with KodiVideoDB(lock=False) as kodidb:
5858
trailer = kodidb.get_trailer(db_item['kodi_id'],
5959
db_item['kodi_type'])
6060
if trailer and (trailer.startswith(f'plugin://{v.ADDON_ID}') or
@@ -103,14 +103,14 @@ def process_fanart(plex_id, plex_type, refresh=False):
103103
done = True
104104
try:
105105
artworks = None
106-
with PlexDB() as plexdb:
106+
with PlexDB(lock=False) as plexdb:
107107
db_item = plexdb.item_by_id(plex_id, plex_type)
108108
if not db_item:
109109
logger.error('Could not get Kodi id for %s %s', plex_type, plex_id)
110110
done = False
111111
return
112112
if not refresh:
113-
with KodiVideoDB() as kodidb:
113+
with KodiVideoDB(lock=False) as kodidb:
114114
artworks = kodidb.get_art(db_item['kodi_id'],
115115
db_item['kodi_type'])
116116
# Check if we even need to get additional art

‎resources/lib/library_sync/sections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def _sync_from_pms(pick_libraries):
649649
if api.plex_type in v.UNSUPPORTED_PLEX_TYPES:
650650
continue
651651
sections.append(Section(index=i, xml_element=xml_element))
652-
with PlexDB() as plexdb:
652+
with PlexDB(lock=False) as plexdb:
653653
for section_db in plexdb.all_sections():
654654
old_sections.append(Section(section_db_element=section_db))
655655
# Update our latest PMS sections with info saved in the PMS DB

‎resources/lib/library_sync/websocket.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,6 @@ def cache_artwork(plex_id, plex_type, kodi_id=None, kodi_type=None):
369369
LOG.error('Could not retrieve Plex db info for %s', plex_id)
370370
return
371371
kodi_id, kodi_type = item['kodi_id'], item['kodi_type']
372-
with kodi_db.KODIDB_FROM_PLEXTYPE[plex_type]() as kodidb:
372+
with kodi_db.KODIDB_FROM_PLEXTYPE[plex_type](lock=False) as kodidb:
373373
for url in kodidb.art_urls(kodi_id, kodi_type):
374374
artwork.cache_url(url)

‎resources/lib/playlists/db.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ def plex_playlist_ids():
2222
"""
2323
Returns a list of all Plex ids of the playlists already in our DB
2424
"""
25-
with PlexDB() as plexdb:
25+
with PlexDB(lock=False) as plexdb:
2626
return list(plexdb.playlist_ids())
2727

2828

2929
def kodi_playlist_paths():
3030
"""
3131
Returns a list of all Kodi playlist paths of the playlists already synced
3232
"""
33-
with PlexDB() as plexdb:
33+
with PlexDB(lock=False) as plexdb:
3434
return list(plexdb.kodi_playlist_paths())
3535

3636

@@ -53,7 +53,7 @@ def get_playlist(path=None, plex_id=None):
5353
Returns the playlist as a Playlist for either the plex_id or path
5454
"""
5555
playlist = Playlist()
56-
with PlexDB() as plexdb:
56+
with PlexDB(lock=False) as plexdb:
5757
playlist = plexdb.playlist(playlist, plex_id, path)
5858
return playlist
5959

@@ -62,7 +62,7 @@ def get_all_kodi_playlist_paths():
6262
"""
6363
Returns a list with all paths for the playlists on the Kodi side
6464
"""
65-
with PlexDB() as plexdb:
65+
with PlexDB(lock=False) as plexdb:
6666
paths = list(plexdb.all_kodi_paths())
6767
return paths
6868

@@ -112,7 +112,7 @@ def m3u_to_plex_ids(playlist):
112112
db_type=playlist.kodi_type)
113113
if not kodi_id:
114114
continue
115-
with PlexDB() as plexdb:
115+
with PlexDB(lock=False) as plexdb:
116116
item = plexdb.item_by_kodi_id(kodi_id, kodi_type)
117117
if item:
118118
plex_ids.append(item['plex_id'])

‎resources/lib/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def wipe_database(reboot=True):
475475
from .playlists import remove_synced_playlists
476476
remove_synced_playlists()
477477
try:
478-
with plex_db.PlexDB() as plexdb:
478+
with plex_db.PlexDB(lock=False) as plexdb:
479479
if plexdb.songs_have_been_synced():
480480
LOG.info('Detected that music has also been synced - wiping music')
481481
music = True

0 commit comments

Comments
 (0)
Please sign in to comment.