From 5d2de1471fa3a9045e1a4bd6d3e61a8bee02eb41 Mon Sep 17 00:00:00 2001 From: codey Date: Tue, 22 Apr 2025 15:49:32 -0400 Subject: [PATCH] small optimization for filtering --- utils/radio_util.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/radio_util.py b/utils/radio_util.py index f002685..e550262 100644 --- a/utils/radio_util.py +++ b/utils/radio_util.py @@ -275,14 +275,16 @@ class RadioUtil: """ try: artist = artist.strip() - query: str = "SELECT genre FROM artist_genre WHERE artist LIKE ? COLLATE NOCASE" + query: str = ( + "SELECT genre FROM artist_genre WHERE artist LIKE ? COLLATE NOCASE" + ) params: tuple[str] = (f"%%{artist}%%",) async with sqlite3.connect(self.artist_genre_db_path, timeout=2) as _db: _db.row_factory = sqlite3.Row async with await _db.execute(query, params) as _cursor: res = await _cursor.fetchone() if not res: - return "Not Found" # Exception suppressed + return "Not Found" # Exception suppressed # raise RadioException( # f"Could not locate {artist} in artist_genre_map db." # ) @@ -358,15 +360,19 @@ class RadioUtil: len(self.active_playlist), ) if self.playback_genres: - new_playlist: list[dict] = [] + new_playlist: list[dict] = [] logging.info("Limiting playback genres") - for x, item in enumerate(self.active_playlist): + for item in self.active_playlist: + matched_genre: bool = False item_genres: str = item.get("genre", "").strip().lower() for genre in self.playback_genres: genre = genre.strip().lower() if genre in item_genres: new_playlist.append(item) + matched_genre = True continue + if matched_genre: + continue self.active_playlist = new_playlist logging.info( "%s items remain for playback after filtering",