Add artist refresh completed event

Always fires unlike update, which only fires on actual update.  Use
this to make sure media covers are up to date on refresh
This commit is contained in:
ta264 2019-07-19 13:40:31 +01:00
commit 77d02a03a0
7 changed files with 34 additions and 28 deletions

View file

@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
.Setup(v => v.FileExists(It.IsAny<string>()))
.Returns(true);
Subject.HandleAsync(new ArtistUpdatedEvent(_artist));
Subject.HandleAsync(new ArtistRefreshCompleteEvent(_artist));
Mocker.GetMock<IImageResizer>()
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(3));
@ -132,7 +132,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
.Setup(v => v.FileExists(It.IsAny<string>()))
.Returns(false);
Subject.HandleAsync(new ArtistUpdatedEvent(_artist));
Subject.HandleAsync(new ArtistRefreshCompleteEvent(_artist));
Mocker.GetMock<IImageResizer>()
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(3));
@ -157,7 +157,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
.Setup(v => v.GetFileSize(It.IsAny<string>()))
.Returns(1000);
Subject.HandleAsync(new ArtistUpdatedEvent(_artist));
Subject.HandleAsync(new ArtistRefreshCompleteEvent(_artist));
Mocker.GetMock<IImageResizer>()
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Never());
@ -182,7 +182,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
.Setup(v => v.GetFileSize(It.IsAny<string>()))
.Returns(0);
Subject.HandleAsync(new ArtistUpdatedEvent(_artist));
Subject.HandleAsync(new ArtistRefreshCompleteEvent(_artist));
Mocker.GetMock<IImageResizer>()
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(3));
@ -207,7 +207,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
.Setup(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()))
.Throws<ApplicationException>();
Subject.HandleAsync(new ArtistUpdatedEvent(_artist));
Subject.HandleAsync(new ArtistRefreshCompleteEvent(_artist));
Mocker.GetMock<IImageResizer>()
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(3));

View file

@ -22,7 +22,7 @@ namespace NzbDrone.Core.MediaCover
}
public class MediaCoverService :
IHandleAsync<ArtistUpdatedEvent>,
IHandleAsync<ArtistRefreshCompleteEvent>,
IHandleAsync<ArtistDeletedEvent>,
IMapCoversToLocal
{
@ -287,7 +287,7 @@ namespace NzbDrone.Core.MediaCover
}
}
public void HandleAsync(ArtistUpdatedEvent message)
public void HandleAsync(ArtistRefreshCompleteEvent message)
{
EnsureArtistCovers(message.Artist);

View file

@ -0,0 +1,14 @@
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.Music.Events
{
public class ArtistRefreshCompleteEvent : IEvent
{
public Artist Artist { get; set; }
public ArtistRefreshCompleteEvent(Artist artist)
{
Artist = artist;
}
}
}

View file

@ -1,18 +0,0 @@
using NzbDrone.Common.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Music.Events
{
public class ArtistRefreshStartingEvent : IEvent
{
public bool ManualTrigger { get; set; }
public ArtistRefreshStartingEvent(bool manualTrigger)
{
ManualTrigger = manualTrigger;
}
}
}

View file

@ -247,6 +247,11 @@ namespace NzbDrone.Core.Music
_eventAggregator.PublishEvent(new ArtistUpdatedEvent(entity));
}
protected virtual void PublishRefreshCompleteEvent(Artist entity)
{
_eventAggregator.PublishEvent(new ArtistRefreshCompleteEvent(entity));
}
protected override void PublishChildrenUpdatedEvent(Artist entity, List<Album> newChildren, List<Album> updateChildren)
{
_eventAggregator.PublishEvent(new AlbumInfoRefreshedEvent(entity, newChildren, updateChildren));
@ -297,7 +302,6 @@ namespace NzbDrone.Core.Music
{
var trigger = message.Trigger;
var isNew = message.IsNewArtist;
_eventAggregator.PublishEvent(new ArtistRefreshStartingEvent(trigger == CommandTrigger.Manual));
if (message.ArtistId.HasValue)
{

View file

@ -100,7 +100,11 @@ namespace NzbDrone.Core.Music
protected virtual void PublishEntityUpdatedEvent(Entity entity)
{
}
protected virtual void PublishRefreshCompleteEvent(Entity entity)
{
}
protected virtual void PublishChildrenUpdatedEvent(Entity entity, List<Child> newChildren, List<Child> updateChildren)
{
}
@ -185,6 +189,8 @@ namespace NzbDrone.Core.Music
PublishEntityUpdatedEvent(local);
}
PublishRefreshCompleteEvent(local);
_logger.Debug($"Finished {typeof(Entity).Name} refresh for {local}");
return updated;

View file

@ -893,7 +893,7 @@
<Compile Include="Music\Events\ArtistDeletedEvent.cs" />
<Compile Include="Music\Events\AlbumEditedEvent.cs" />
<Compile Include="Music\Events\ArtistEditedEvent.cs" />
<Compile Include="Music\Events\ArtistRefreshStartingEvent.cs" />
<Compile Include="Music\Events\ArtistRefreshCompleteEvent.cs" />
<Compile Include="Music\Events\ArtistUpdatedEvent.cs" />
<Compile Include="Music\Events\AlbumInfoRefreshedEvent.cs" />
<Compile Include="Music\Ratings.cs" />