don't modify lists while iterating through them

This commit is contained in:
George Lacey 2025-07-12 15:01:01 +01:00
parent 875ed7a668
commit cc9b560484

View File

@ -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)
if len(left.by_name()) > len(existing_albums):
self.log.info('PRN', f"Pruned album: {album_name}")