Merge branch 'xem-caching' into develop
This commit is contained in:
commit
b821f44cfa
|
@ -2,7 +2,9 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.Cache;
|
||||||
using NzbDrone.Common.Messaging;
|
using NzbDrone.Common.Messaging;
|
||||||
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
using NzbDrone.Core.Tv.Events;
|
using NzbDrone.Core.Tv.Events;
|
||||||
|
|
||||||
|
@ -12,31 +14,37 @@ namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
void UpdateMappings();
|
void UpdateMappings();
|
||||||
void UpdateMappings(int seriesId);
|
void UpdateMappings(int seriesId);
|
||||||
|
void UpdateMappings(Series series);
|
||||||
void PerformUpdate(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 IEpisodeService _episodeService;
|
||||||
private readonly IXemCommunicationProvider _xemCommunicationProvider;
|
private readonly IXemCommunicationProvider _xemCommunicationProvider;
|
||||||
private readonly ISeriesService _seriesService;
|
private readonly ISeriesService _seriesService;
|
||||||
|
private readonly ICached<bool> _cache;
|
||||||
|
|
||||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
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");
|
if (seriesService == null) throw new ArgumentNullException("seriesService");
|
||||||
_episodeService = episodeService;
|
_episodeService = episodeService;
|
||||||
_xemCommunicationProvider = xemCommunicationProvider;
|
_xemCommunicationProvider = xemCommunicationProvider;
|
||||||
_seriesService = seriesService;
|
_seriesService = seriesService;
|
||||||
|
_cache = cacheManger.GetCache<bool>(GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateMappings()
|
public void UpdateMappings()
|
||||||
{
|
{
|
||||||
_logger.Trace("Starting scene numbering update");
|
_logger.Trace("Starting scene numbering update");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var ids = _xemCommunicationProvider.GetXemSeriesIds();
|
var ids = GetXemSeriesIds();
|
||||||
var series = _seriesService.GetAllSeries();
|
var series = _seriesService.GetAllSeries();
|
||||||
var wantedSeries = series.Where(s => ids.Contains(s.TvdbId)).ToList();
|
var wantedSeries = series.Where(s => ids.Contains(s.TvdbId)).ToList();
|
||||||
|
|
||||||
|
@ -64,12 +72,15 @@ namespace NzbDrone.Core.Providers
|
||||||
_logger.Trace("Series could not be found: {0}", seriesId);
|
_logger.Trace("Series could not be found: {0}", seriesId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateMappings(series);
|
||||||
|
}
|
||||||
|
|
||||||
var xemIds = _xemCommunicationProvider.GetXemSeriesIds();
|
public void UpdateMappings(Series series)
|
||||||
|
{
|
||||||
if (!xemIds.Contains(series.TvdbId))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +136,20 @@ namespace NzbDrone.Core.Providers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
public void Execute(UpdateXemMappingsCommand message)
|
||||||
{
|
{
|
||||||
if (message.SeriesId.HasValue)
|
if (message.SeriesId.HasValue)
|
||||||
|
@ -139,7 +164,12 @@ namespace NzbDrone.Core.Providers
|
||||||
|
|
||||||
public void Handle(SeriesUpdatedEvent message)
|
public void Handle(SeriesUpdatedEvent message)
|
||||||
{
|
{
|
||||||
PerformUpdate(message.Series);
|
UpdateMappings(message.Series);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleAsync(ApplicationStartedEvent message)
|
||||||
|
{
|
||||||
|
GetXemSeriesIds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue