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
parent 8160f3d84a
commit 77d02a03a0
7 changed files with 34 additions and 28 deletions

View file

@ -111,7 +111,7 @@ public void should_resize_covers_if_main_downloaded()
.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 @@ public void should_resize_covers_if_missing()
.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 @@ public void should_not_resize_covers_if_exists()
.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 @@ public void should_resize_covers_if_existing_is_empty()
.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 @@ public void should_log_error_if_resize_failed()
.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 @@ public interface IMapCoversToLocal
}
public class MediaCoverService :
IHandleAsync<ArtistUpdatedEvent>,
IHandleAsync<ArtistRefreshCompleteEvent>,
IHandleAsync<ArtistDeletedEvent>,
IMapCoversToLocal
{
@ -287,7 +287,7 @@ private int[] GetDefaultHeights(MediaCoverTypes coverType)
}
}
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 @@ protected override void PublishEntityUpdatedEvent(Artist entity)
_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 @@ public void Execute(RefreshArtistCommand message)
{
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 @@ protected virtual UpdateResult MergeEntity(Entity local, Entity target, Entity r
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 @@ public bool RefreshEntityInfo(Entity local, List<Entity> remoteList, bool forceC
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" />