From a73d89bc9ece34efaee65c08acfe7cf057c29e80 Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Mon, 22 Sep 2025 15:15:34 -0700 Subject: [PATCH] Update plex_client.py --- core/plex_client.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/plex_client.py b/core/plex_client.py index 0e6887d..3a3b201 100644 --- a/core/plex_client.py +++ b/core/plex_client.py @@ -80,6 +80,8 @@ class PlexClient: self.music_library: Optional[MusicSection] = None self._connection_attempted = False self._is_connecting = False + self._last_connection_check = 0 # Cache connection checks + self._connection_check_interval = 30 # Check every 30 seconds max def ensure_connection(self) -> bool: """Ensure connection to Plex server with lazy initialization.""" @@ -159,11 +161,21 @@ class PlexClient: logger.error(f"Error finding music library: {e}") def is_connected(self) -> bool: - """Check if connected to Plex server with lazy initialization.""" - if not self._connection_attempted: + """Check if connected to Plex server with cached connection checks.""" + import time + + current_time = time.time() + + # Only check connection if enough time has passed or never attempted + if (not self._connection_attempted or + current_time - self._last_connection_check > self._connection_check_interval): + + self._last_connection_check = current_time + # Try to connect on first call, but don't block if already connecting if not self._is_connecting: self.ensure_connection() + return self.server is not None and self.music_library is not None def get_all_playlists(self) -> List[PlexPlaylistInfo]: