mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 03:52:33 +02:00
Merge branch 'xem-caching' into develop
This commit is contained in:
commit
b821f44cfa
@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Tv.Events;
|
||||
|
||||
@ -12,31 +14,37 @@ public interface IXemProvider
|
||||
{
|
||||
void UpdateMappings();
|
||||
void UpdateMappings(int seriesId);
|
||||
void UpdateMappings(Series series);
|
||||
void PerformUpdate(Series series);
|
||||
}
|
||||
|
||||
public class XemProvider : IXemProvider, IExecute<UpdateXemMappingsCommand>, IHandle<SeriesUpdatedEvent>
|
||||
public class XemProvider : IXemProvider, IExecute<UpdateXemMappingsCommand>, IHandle<SeriesUpdatedEvent>, IHandleAsync<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly IXemCommunicationProvider _xemCommunicationProvider;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly ICached<bool> _cache;
|
||||
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public XemProvider(IEpisodeService episodeService, IXemCommunicationProvider xemCommunicationProvider, ISeriesService seriesService)
|
||||
public XemProvider(IEpisodeService episodeService,
|
||||
IXemCommunicationProvider xemCommunicationProvider,
|
||||
ISeriesService seriesService, ICacheManger cacheManger)
|
||||
{
|
||||
if (seriesService == null) throw new ArgumentNullException("seriesService");
|
||||
_episodeService = episodeService;
|
||||
_xemCommunicationProvider = xemCommunicationProvider;
|
||||
_seriesService = seriesService;
|
||||
_cache = cacheManger.GetCache<bool>(GetType());
|
||||
}
|
||||
|
||||
public void UpdateMappings()
|
||||
{
|
||||
_logger.Trace("Starting scene numbering update");
|
||||
|
||||
try
|
||||
{
|
||||
var ids = _xemCommunicationProvider.GetXemSeriesIds();
|
||||
var ids = GetXemSeriesIds();
|
||||
var series = _seriesService.GetAllSeries();
|
||||
var wantedSeries = series.Where(s => ids.Contains(s.TvdbId)).ToList();
|
||||
|
||||
@ -64,12 +72,15 @@ public void UpdateMappings(int seriesId)
|
||||
_logger.Trace("Series could not be found: {0}", seriesId);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateMappings(series);
|
||||
}
|
||||
|
||||
var xemIds = _xemCommunicationProvider.GetXemSeriesIds();
|
||||
|
||||
if (!xemIds.Contains(series.TvdbId))
|
||||
public void UpdateMappings(Series series)
|
||||
{
|
||||
if (!_cache.Find(series.TvdbId.ToString()))
|
||||
{
|
||||
_logger.Trace("Xem doesn't have a mapping for this series: {0}", series.TvdbId);
|
||||
_logger.Trace("Scene numbering is not available for {0} [{1}]", series.Title, series.TvdbId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -125,6 +136,20 @@ public void PerformUpdate(Series series)
|
||||
}
|
||||
}
|
||||
|
||||
private List<int> GetXemSeriesIds()
|
||||
{
|
||||
_cache.Clear();
|
||||
|
||||
var ids = _xemCommunicationProvider.GetXemSeriesIds();
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
_cache.Set(id.ToString(), true);
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void Execute(UpdateXemMappingsCommand message)
|
||||
{
|
||||
if (message.SeriesId.HasValue)
|
||||
@ -139,7 +164,12 @@ public void Execute(UpdateXemMappingsCommand message)
|
||||
|
||||
public void Handle(SeriesUpdatedEvent message)
|
||||
{
|
||||
PerformUpdate(message.Series);
|
||||
UpdateMappings(message.Series);
|
||||
}
|
||||
|
||||
public void HandleAsync(ApplicationStartedEvent message)
|
||||
{
|
||||
GetXemSeriesIds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user