From c1dd253bc1acc6acad5ec09de14b3c8432348bf0 Mon Sep 17 00:00:00 2001 From: ta264 Date: Wed, 3 Aug 2022 21:05:28 +0100 Subject: [PATCH] Fixed: Correctly add missing new artist when an album's artist changes in musicbrainz Fixes LIDARR-H --- src/Lidarr.Api.V1/Artist/ArtistController.cs | 7 +++++++ .../ArtistStats/ArtistStatisticsService.cs | 16 ++++++++++++++++ .../Music/Services/RefreshAlbumService.cs | 6 +++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Lidarr.Api.V1/Artist/ArtistController.cs b/src/Lidarr.Api.V1/Artist/ArtistController.cs index f5a874f7d..1c185a35b 100644 --- a/src/Lidarr.Api.V1/Artist/ArtistController.cs +++ b/src/Lidarr.Api.V1/Artist/ArtistController.cs @@ -31,6 +31,7 @@ namespace Lidarr.Api.V1.Artist IHandle, IHandle, IHandle, + IHandle, IHandle, IHandle, IHandle, @@ -284,6 +285,12 @@ namespace Lidarr.Api.V1.Artist BroadcastResourceChange(ModelAction.Updated, GetArtistResource(message.TrackFile.Artist.Value)); } + [NonAction] + public void Handle(ArtistAddedEvent message) + { + BroadcastResourceChange(ModelAction.Updated, GetArtistResource(message.Artist)); + } + [NonAction] public void Handle(ArtistUpdatedEvent message) { diff --git a/src/NzbDrone.Core/ArtistStats/ArtistStatisticsService.cs b/src/NzbDrone.Core/ArtistStats/ArtistStatisticsService.cs index c00ee5948..1ef4936ab 100644 --- a/src/NzbDrone.Core/ArtistStats/ArtistStatisticsService.cs +++ b/src/NzbDrone.Core/ArtistStats/ArtistStatisticsService.cs @@ -15,12 +15,14 @@ namespace NzbDrone.Core.ArtistStats } public class ArtistStatisticsService : IArtistStatisticsService, + IHandle, IHandle, IHandle, IHandle, IHandle, IHandle, IHandle, + IHandle, IHandle { private readonly IArtistStatisticsRepository _artistStatisticsRepository; @@ -68,6 +70,13 @@ namespace NzbDrone.Core.ArtistStats return artistStatistics; } + [EventHandleOrder(EventHandleOrder.First)] + public void Handle(ArtistAddedEvent message) + { + _cache.Remove("AllArtists"); + _cache.Remove(message.Artist.Id.ToString()); + } + [EventHandleOrder(EventHandleOrder.First)] public void Handle(ArtistUpdatedEvent message) { @@ -114,6 +123,13 @@ namespace NzbDrone.Core.ArtistStats _cache.Remove(message.Album.ArtistId.ToString()); } + [EventHandleOrder(EventHandleOrder.First)] + public void Handle(AlbumUpdatedEvent message) + { + _cache.Remove("AllArtists"); + _cache.Remove(message.Album.ArtistId.ToString()); + } + [EventHandleOrder(EventHandleOrder.First)] public void Handle(TrackFileDeletedEvent message) { diff --git a/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs b/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs index 7bcb3857f..a9a271f8f 100644 --- a/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs +++ b/src/NzbDrone.Core/Music/Services/RefreshAlbumService.cs @@ -14,6 +14,7 @@ using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Music.Commands; using NzbDrone.Core.Music.Events; +using NzbDrone.Core.RootFolders; namespace NzbDrone.Core.Music { @@ -27,6 +28,7 @@ namespace NzbDrone.Core.Music { private readonly IAlbumService _albumService; private readonly IArtistService _artistService; + private readonly IRootFolderService _rootFolderService; private readonly IAddArtistService _addArtistService; private readonly IReleaseService _releaseService; private readonly IProvideAlbumInfo _albumInfo; @@ -41,6 +43,7 @@ namespace NzbDrone.Core.Music public RefreshAlbumService(IAlbumService albumService, IArtistService artistService, + IRootFolderService rootFolderService, IAddArtistService addArtistService, IArtistMetadataService artistMetadataService, IReleaseService releaseService, @@ -57,6 +60,7 @@ namespace NzbDrone.Core.Music { _albumService = albumService; _artistService = artistService; + _rootFolderService = rootFolderService; _addArtistService = addArtistService; _releaseService = releaseService; _albumInfo = albumInfo; @@ -123,7 +127,7 @@ namespace NzbDrone.Core.Music Metadata = remote.ArtistMetadata.Value, MetadataProfileId = oldArtist.MetadataProfileId, QualityProfileId = oldArtist.QualityProfileId, - RootFolderPath = oldArtist.RootFolderPath, + RootFolderPath = _rootFolderService.GetBestRootFolderPath(oldArtist.Path), Monitored = oldArtist.Monitored, Tags = oldArtist.Tags };