From: Marcel van der Veldt Date: Wed, 6 Jul 2022 14:41:30 +0000 (+0200) Subject: Update artists.py X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=cab585d2f9238d63ed3ce764d11dffcc4fdaefda;p=music-assistant-server.git Update artists.py --- diff --git a/music_assistant/controllers/music/artists.py b/music_assistant/controllers/music/artists.py index 9b4ba3b8..59a65e7b 100644 --- a/music_assistant/controllers/music/artists.py +++ b/music_assistant/controllers/music/artists.py @@ -177,31 +177,28 @@ class ArtistsController(MediaControllerBase[Artist]): ) -> Artist: """Add a new item record to the database.""" assert item.provider_ids, "Artist is missing provider id(s)" - async with self.mass.database.get_db(db) as db: - # always try to grab existing item by musicbrainz_id - cur_item = None - if item.musicbrainz_id: - match = {"musicbrainz_id": item.musicbrainz_id} - cur_item = await self.mass.database.get_row(self.db_table, match, db=db) - if not cur_item: - # fallback to matching - # NOTE: we match an artist by name which could theoretically lead to collisions - # but the chance is so small it is not worth the additional overhead of grabbing - # the musicbrainz id upfront - match = {"sort_name": item.sort_name} - for row in await self.mass.database.get_rows( - self.db_table, match, db=db - ): - row_artist = Artist.from_db_row(row) - if row_artist.sort_name == item.sort_name: - # just to be sure ?! - cur_item = row_artist - break - if cur_item: - # update existing - return await self.update_db_item( - cur_item.item_id, item, overwrite=overwrite_existing, db=db - ) + # always try to grab existing item by musicbrainz_id + cur_item = None + if item.musicbrainz_id: + match = {"musicbrainz_id": item.musicbrainz_id} + cur_item = await self.mass.database.get_row(self.db_table, match) + if not cur_item: + # fallback to matching + # NOTE: we match an artist by name which could theoretically lead to collisions + # but the chance is so small it is not worth the additional overhead of grabbing + # the musicbrainz id upfront + match = {"sort_name": item.sort_name} + for row in await self.mass.database.get_rows(self.db_table, match): + row_artist = Artist.from_db_row(row) + if row_artist.sort_name == item.sort_name: + # just to be sure ?! + cur_item = row_artist + break + if cur_item: + # update existing + return await self.update_db_item( + cur_item.item_id, item, overwrite=overwrite_existing + ) # insert item if item.in_library and not item.timestamp: