Fixed: Refresh cache for tracked queue on artist/album add or removal

Prevents a NullRef in CompletedDownloadService.VerifyImport when publishing DownloadCompletedEvent for an already cached tracked download
pull/5404/head
Bogdan 7 months ago
parent 2997c16346
commit 031f32a52c

@ -16,7 +16,7 @@ using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download.TrackedDownloads
{
public interface ITrackedDownloadService : IHandle<AlbumDeletedEvent>
public interface ITrackedDownloadService
{
TrackedDownload Find(string downloadId);
void StopTracking(string downloadId);
@ -26,13 +26,16 @@ namespace NzbDrone.Core.Download.TrackedDownloads
void UpdateTrackable(List<TrackedDownload> trackedDownloads);
}
public class TrackedDownloadService : ITrackedDownloadService
public class TrackedDownloadService : ITrackedDownloadService,
IHandle<AlbumInfoRefreshedEvent>,
IHandle<AlbumDeletedEvent>,
IHandle<ArtistAddedEvent>,
IHandle<ArtistsDeletedEvent>
{
private readonly IParsingService _parsingService;
private readonly IHistoryService _historyService;
private readonly IEventAggregator _eventAggregator;
private readonly IDownloadHistoryService _downloadHistoryService;
private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported;
private readonly ICustomFormatCalculationService _formatCalculator;
private readonly Logger _logger;
private readonly ICached<TrackedDownload> _cache;
@ -43,7 +46,6 @@ namespace NzbDrone.Core.Download.TrackedDownloads
ICustomFormatCalculationService formatCalculator,
IEventAggregator eventAggregator,
IDownloadHistoryService downloadHistoryService,
ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported,
Logger logger)
{
_parsingService = parsingService;
@ -51,7 +53,6 @@ namespace NzbDrone.Core.Download.TrackedDownloads
_cache = cacheManager.GetCache<TrackedDownload>(GetType());
_formatCalculator = formatCalculator;
_eventAggregator = eventAggregator;
_trackedDownloadAlreadyImported = trackedDownloadAlreadyImported;
_downloadHistoryService = downloadHistoryService;
_logger = logger;
}
@ -264,18 +265,6 @@ namespace NzbDrone.Core.Download.TrackedDownloads
}
}
public void Handle(AlbumDeletedEvent message)
{
var cachedItems = _cache.Values.Where(x => x.RemoteAlbum != null && x.RemoteAlbum.Albums.Any(a => a.Id == message.Album.Id)).ToList();
if (cachedItems.Any())
{
cachedItems.ForEach(UpdateCachedItem);
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(GetTrackedDownloads()));
}
}
public void Handle(AlbumInfoRefreshedEvent message)
{
var needsToUpdate = false;
@ -301,12 +290,45 @@ namespace NzbDrone.Core.Download.TrackedDownloads
}
}
public void Handle(AlbumDeletedEvent message)
{
var cachedItems = _cache.Values
.Where(t =>
t.RemoteAlbum?.Albums != null &&
t.RemoteAlbum.Albums.Any(a => a.Id == message.Album.Id || a.ForeignAlbumId == message.Album.ForeignAlbumId))
.ToList();
if (cachedItems.Any())
{
cachedItems.ForEach(UpdateCachedItem);
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(GetTrackedDownloads()));
}
}
public void Handle(ArtistAddedEvent message)
{
var cachedItems = _cache.Values
.Where(t =>
t.RemoteAlbum?.Artist == null ||
message.Artist?.ForeignArtistId == t.RemoteAlbum.Artist.ForeignArtistId)
.ToList();
if (cachedItems.Any())
{
cachedItems.ForEach(UpdateCachedItem);
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(GetTrackedDownloads()));
}
}
public void Handle(ArtistsDeletedEvent message)
{
var cachedItems = _cache.Values.Where(t =>
t.RemoteAlbum?.Artist != null &&
message.Artists.Select(a => a.Id).Contains(t.RemoteAlbum.Artist.Id))
.ToList();
var cachedItems = _cache.Values
.Where(t =>
t.RemoteAlbum?.Artist != null &&
message.Artists.Any(a => a.Id == t.RemoteAlbum.Artist.Id || a.ForeignArtistId == t.RemoteAlbum.Artist.ForeignArtistId))
.ToList();
if (cachedItems.Any())
{

Loading…
Cancel
Save