New: Refresh cache for tracked queue on series add

This commit is contained in:
Bogdan 2024-05-30 00:25:51 +03:00 committed by Mark McDowall
parent e07eb05e8b
commit ea54ade9bf
1 changed files with 22 additions and 4 deletions

View File

@ -28,6 +28,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
public class TrackedDownloadService : ITrackedDownloadService, public class TrackedDownloadService : ITrackedDownloadService,
IHandle<EpisodeInfoRefreshedEvent>, IHandle<EpisodeInfoRefreshedEvent>,
IHandle<SeriesAddedEvent>,
IHandle<SeriesDeletedEvent> IHandle<SeriesDeletedEvent>
{ {
private readonly IParsingService _parsingService; private readonly IParsingService _parsingService;
@ -278,12 +279,29 @@ namespace NzbDrone.Core.Download.TrackedDownloads
} }
} }
public void Handle(SeriesAddedEvent message)
{
var cachedItems = _cache.Values
.Where(t =>
t.RemoteEpisode?.Series == null ||
message.Series?.TvdbId == t.RemoteEpisode.Series.TvdbId)
.ToList();
if (cachedItems.Any())
{
cachedItems.ForEach(UpdateCachedItem);
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(GetTrackedDownloads()));
}
}
public void Handle(SeriesDeletedEvent message) public void Handle(SeriesDeletedEvent message)
{ {
var cachedItems = _cache.Values.Where(t => var cachedItems = _cache.Values
t.RemoteEpisode?.Series != null && .Where(t =>
message.Series.Any(s => s.Id == t.RemoteEpisode.Series.Id)) t.RemoteEpisode?.Series != null &&
.ToList(); message.Series.Any(s => s.Id == t.RemoteEpisode.Series.Id || s.TvdbId == t.RemoteEpisode.Series.TvdbId))
.ToList();
if (cachedItems.Any()) if (cachedItems.Any())
{ {