1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-25 17:17:12 +00:00

Fixed events storm to UI on SignalR (re)connection with large libraries.

This commit is contained in:
morpheus65535 2021-05-18 15:41:29 -04:00
parent 2643023240
commit bf8c4caef7
4 changed files with 44 additions and 37 deletions

View file

@ -38,11 +38,12 @@ def sync_episodes(send_event=True):
series_count = len(seriesIdList)
for i, seriesId in enumerate(seriesIdList, 1):
show_progress(id='episodes_progress',
header='Syncing episodes...',
name=seriesId['title'],
value=i,
count=series_count)
if send_event:
show_progress(id='episodes_progress',
header='Syncing episodes...',
name=seriesId['title'],
value=i,
count=series_count)
# Get episodes data for a series from Sonarr
episodes = get_episodes_from_sonarr_api(url=url_sonarr(), apikey_sonarr=apikey_sonarr,
@ -64,13 +65,14 @@ def sync_episodes(send_event=True):
else:
episodes_to_add.append(episodeParser(episode))
show_progress(id='episodes_progress',
header='Syncing episodes...',
name='Completed successfully',
value=series_count,
count=series_count)
if send_event:
show_progress(id='episodes_progress',
header='Syncing episodes...',
name='Completed successfully',
value=series_count,
count=series_count)
hide_progress(id='episodes_progress')
hide_progress(id='episodes_progress')
# Remove old episodes from DB
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
@ -79,7 +81,8 @@ def sync_episodes(send_event=True):
episode_to_delete = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId FROM table_episodes WHERE "
"sonarrEpisodeId=?", (removed_episode,), only_one=True)
database.execute("DELETE FROM table_episodes WHERE sonarrEpisodeId=?", (removed_episode,))
event_stream(type='episode', action='delete', payload=episode_to_delete['sonarrEpisodeId'])
if send_event:
event_stream(type='episode', action='delete', payload=episode_to_delete['sonarrEpisodeId'])
# Update existing episodes in DB
episode_in_db_list = []

View file

@ -62,11 +62,12 @@ def update_movies(send_event=True):
# Build new and updated movies
movies_count = len(movies)
for i, movie in enumerate(movies, 1):
show_progress(id='movies_progress',
header='Syncing movies...',
name=movie['title'],
value=i,
count=movies_count)
if send_event:
show_progress(id='movies_progress',
header='Syncing movies...',
name=movie['title'],
value=i,
count=movies_count)
if movie['hasFile'] is True:
if 'movieFile' in movie:
@ -87,13 +88,14 @@ def update_movies(send_event=True):
movie_default_profile=movie_default_profile,
audio_profiles=audio_profiles))
show_progress(id='movies_progress',
header='Syncing movies...',
name='Completed successfully',
value=movies_count,
count=movies_count)
if send_event:
show_progress(id='movies_progress',
header='Syncing movies...',
name='Completed successfully',
value=movies_count,
count=movies_count)
hide_progress(id='movies_progress')
hide_progress(id='movies_progress')
# Remove old movies from DB
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))

View file

@ -49,11 +49,12 @@ def update_series(send_event=True):
series_count = len(series)
for i, show in enumerate(series, 1):
show_progress(id='series_progress',
header='Syncing series...',
name=show['title'],
value=i,
count=series_count)
if send_event:
show_progress(id='series_progress',
header='Syncing series...',
name=show['title'],
value=i,
count=series_count)
# Add shows in Sonarr to current shows list
current_shows_sonarr.append(show['id'])
@ -67,13 +68,14 @@ def update_series(send_event=True):
tags_dict=tagsDict, serie_default_profile=serie_default_profile,
audio_profiles=audio_profiles))
show_progress(id='series_progress',
header='Syncing series...',
name='Completed successfully',
value=series_count,
count=series_count)
if send_event:
show_progress(id='series_progress',
header='Syncing series...',
name='Completed successfully',
value=series_count,
count=series_count)
hide_progress(id='series_progress')
hide_progress(id='series_progress')
# Remove old series from DB
removed_series = list(set(current_shows_db_list) - set(current_shows_sonarr))

View file

@ -43,8 +43,8 @@ class SonarrSignalrClient:
self.stop()
logging.info('BAZARR SignalR client for Sonarr is connected and waiting for events.')
if not args.dev:
scheduler.execute_job_now('update_series')
scheduler.execute_job_now('sync_episodes')
scheduler.add_job(update_series, kwargs={'send_event': False}, max_instances=1)
scheduler.add_job(sync_episodes, kwargs={'send_event': False}, max_instances=1)
def stop(self, log=True):
try:
@ -106,7 +106,7 @@ class RadarrSignalrClient:
def on_connect_handler():
logging.info('BAZARR SignalR client for Radarr is connected and waiting for events.')
if not args.dev:
scheduler.execute_job_now('update_movies')
scheduler.add_job(update_movies, kwargs={'send_event': False}, max_instances=1)
def configure(self):
self.apikey_radarr = settings.radarr.apikey