From bf8c4caef7d4f819e2f5704b345c3d056ca103a9 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Tue, 18 May 2021 15:41:29 -0400 Subject: [PATCH] Fixed events storm to UI on SignalR (re)connection with large libraries. --- bazarr/get_episodes.py | 27 +++++++++++++++------------ bazarr/get_movies.py | 24 +++++++++++++----------- bazarr/get_series.py | 24 +++++++++++++----------- bazarr/signalr_client.py | 6 +++--- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 9acbd55e5..b0e6c16d3 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -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 = [] diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index c5f256c8c..0708697a0 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -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)) diff --git a/bazarr/get_series.py b/bazarr/get_series.py index 98257b8b5..e3dc1030d 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -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)) diff --git a/bazarr/signalr_client.py b/bazarr/signalr_client.py index 5037a47a8..305c11c48 100644 --- a/bazarr/signalr_client.py +++ b/bazarr/signalr_client.py @@ -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