From cc9b560484bab22bf508f3b478d1bf74c6482afd Mon Sep 17 00:00:00 2001 From: grglcy Date: Sat, 12 Jul 2025 15:01:01 +0100 Subject: [PATCH] don't modify lists while iterating through them --- src/layers/dedupe.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/layers/dedupe.py b/src/layers/dedupe.py index e29b353..e641dcc 100644 --- a/src/layers/dedupe.py +++ b/src/layers/dedupe.py @@ -12,20 +12,22 @@ class Dedupe(Layer): def _process(self, left: Root): right = self.other existing_artists = right.by_name() + pruned_artists = list() for artist in left: artist_name = artist.name if artist_name in existing_artists: self.prune_artist(artist, right[artist_name]) if len(artist.contents) == 0: - left.prune(artist_name) + pruned_artists.append(artist_name) self.log.info('PRN', f"Pruned artist: {artist_name}") else: continue # todo: fuzzy matching + [left.prune(artist) for artist in pruned_artists] def prune_artist(self, left: Artist, right: Artist): existing_albums = right.by_name() - for album in left: - album_name = album.name - if album_name in existing_albums: + for album_name in existing_albums: + if album_name in left.by_name(): left.prune(album_name) - self.log.info('PRN', f"Pruned album: {album_name}") + if len(left.by_name()) > len(existing_albums): + self.log.info('PRN', f"Pruned album: {album_name}")