Skip to content

Commit

Permalink
Add artist refresh completed event
Browse files Browse the repository at this point in the history
Always fires unlike update, which only fires on actual update.  Use
this to make sure media covers are up to date on refresh
  • Loading branch information
ta264 committed Jul 24, 2019
1 parent 8160f3d commit 77d02a0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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());
Expand All @@ -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));
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/NzbDrone.Core/MediaCover/MediaCoverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IMapCoversToLocal
}

public class MediaCoverService :
IHandleAsync<ArtistUpdatedEvent>,
IHandleAsync<ArtistRefreshCompleteEvent>,
IHandleAsync<ArtistDeletedEvent>,
IMapCoversToLocal
{
Expand Down Expand Up @@ -287,7 +287,7 @@ private int[] GetDefaultHeights(MediaCoverTypes coverType)
}
}

public void HandleAsync(ArtistUpdatedEvent message)
public void HandleAsync(ArtistRefreshCompleteEvent message)
{
EnsureArtistCovers(message.Artist);

Expand Down
14 changes: 14 additions & 0 deletions src/NzbDrone.Core/Music/Events/ArtistRefreshCompleteEvent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
18 changes: 0 additions & 18 deletions src/NzbDrone.Core/Music/Events/ArtistRefreshStartingEvent.cs

This file was deleted.

6 changes: 5 additions & 1 deletion src/NzbDrone.Core/Music/RefreshArtistService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 7 additions & 1 deletion src/NzbDrone.Core/Music/RefreshEntityServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/NzbDrone.Core/NzbDrone.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

0 comments on commit 77d02a0

Please sign in to comment.