|
|
|
@ -4,6 +4,7 @@ using NLog;
|
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
|
using System;
|
|
|
|
|
using NzbDrone.Common.Cache;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Qualities
|
|
|
|
|
{
|
|
|
|
@ -17,22 +18,31 @@ namespace NzbDrone.Core.Qualities
|
|
|
|
|
public class QualityDefinitionService : IQualityDefinitionService, IHandle<ApplicationStartedEvent>
|
|
|
|
|
{
|
|
|
|
|
private readonly IQualityDefinitionRepository _qualityDefinitionRepository;
|
|
|
|
|
private readonly ICached<Dictionary<Quality, QualityDefinition>> _cache;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public QualityDefinitionService(IQualityDefinitionRepository qualityDefinitionRepository, Logger logger)
|
|
|
|
|
public QualityDefinitionService(IQualityDefinitionRepository qualityDefinitionRepository, ICacheManager cacheManager, Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_qualityDefinitionRepository = qualityDefinitionRepository;
|
|
|
|
|
_cache = cacheManager.GetCache<Dictionary<Quality, QualityDefinition>>(this.GetType());
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dictionary<Quality, QualityDefinition> GetAll()
|
|
|
|
|
{
|
|
|
|
|
return _cache.Get("all", () => _qualityDefinitionRepository.All().ToDictionary(v => v.Quality), TimeSpan.FromSeconds(5.0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(QualityDefinition qualityDefinition)
|
|
|
|
|
{
|
|
|
|
|
_qualityDefinitionRepository.Update(qualityDefinition);
|
|
|
|
|
|
|
|
|
|
_cache.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<QualityDefinition> All()
|
|
|
|
|
{
|
|
|
|
|
return _qualityDefinitionRepository.All().ToList();
|
|
|
|
|
return GetAll().Values.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public QualityDefinition Get(Quality quality)
|
|
|
|
@ -40,7 +50,7 @@ namespace NzbDrone.Core.Qualities
|
|
|
|
|
if (quality == Quality.Unknown)
|
|
|
|
|
return new QualityDefinition(Quality.Unknown);
|
|
|
|
|
|
|
|
|
|
return _qualityDefinitionRepository.GetByQualityId((int)quality);
|
|
|
|
|
return GetAll()[quality];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InsertMissingDefinitions(List<QualityDefinition> allDefinitions)
|
|
|
|
@ -89,10 +99,12 @@ namespace NzbDrone.Core.Qualities
|
|
|
|
|
_qualityDefinitionRepository.Update(existingDefinitions[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cache.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(ApplicationStartedEvent message)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Setting up default quality config");
|
|
|
|
|
|
|
|
|
|
InsertMissingDefinitions(Quality.DefaultQualityDefinitions.ToList());
|
|
|
|
|