mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
Refresh the scene mapping cache if it is empty during a lookup
This commit is contained in:
parent
53c2962d2a
commit
438686ca1a
6 changed files with 68 additions and 22 deletions
|
@ -15,8 +15,8 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
|||
public interface ISceneMappingService
|
||||
{
|
||||
List<String> GetSceneNames(int tvdbId, IEnumerable<Int32> seasonNumbers);
|
||||
Nullable<int> GetTvDbId(string title);
|
||||
List<SceneMapping> FindByTvdbid(int tvdbId);
|
||||
Nullable<int> FindTvDbId(string title);
|
||||
List<SceneMapping> FindByTvdbId(int tvdbId);
|
||||
Nullable<Int32> GetSeasonNumber(string title);
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
|||
private readonly ISceneMappingRepository _repository;
|
||||
private readonly IEnumerable<ISceneMappingProvider> _sceneMappingProviders;
|
||||
private readonly Logger _logger;
|
||||
private readonly ICached<SceneMapping> _gettvdbIdCache;
|
||||
private readonly ICached<List<SceneMapping>> _findbytvdbIdCache;
|
||||
private readonly ICached<SceneMapping> _getTvdbIdCache;
|
||||
private readonly ICached<List<SceneMapping>> _findByTvdbIdCache;
|
||||
|
||||
public SceneMappingService(ISceneMappingRepository repository,
|
||||
ICacheManager cacheManager,
|
||||
|
@ -39,14 +39,14 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
|||
_repository = repository;
|
||||
_sceneMappingProviders = sceneMappingProviders;
|
||||
|
||||
_gettvdbIdCache = cacheManager.GetCache<SceneMapping>(GetType(), "tvdb_id");
|
||||
_findbytvdbIdCache = cacheManager.GetCache<List<SceneMapping>>(GetType(), "find_tvdb_id");
|
||||
_getTvdbIdCache = cacheManager.GetCache<SceneMapping>(GetType(), "tvdb_id");
|
||||
_findByTvdbIdCache = cacheManager.GetCache<List<SceneMapping>>(GetType(), "find_tvdb_id");
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<String> GetSceneNames(int tvdbId, IEnumerable<Int32> seasonNumbers)
|
||||
{
|
||||
var names = _findbytvdbIdCache.Find(tvdbId.ToString());
|
||||
var names = _findByTvdbIdCache.Find(tvdbId.ToString());
|
||||
|
||||
if (names == null)
|
||||
{
|
||||
|
@ -58,9 +58,9 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
|||
.Select(m => m.SearchTerm).Distinct().ToList());
|
||||
}
|
||||
|
||||
public Nullable<Int32> GetTvDbId(string title)
|
||||
public Nullable<Int32> FindTvDbId(string title)
|
||||
{
|
||||
var mapping = _gettvdbIdCache.Find(title.CleanSeriesTitle());
|
||||
var mapping = FindTvdbId(title);
|
||||
|
||||
if (mapping == null)
|
||||
return null;
|
||||
|
@ -68,9 +68,14 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
|||
return mapping.TvdbId;
|
||||
}
|
||||
|
||||
public List<SceneMapping> FindByTvdbid(int tvdbId)
|
||||
public List<SceneMapping> FindByTvdbId(int tvdbId)
|
||||
{
|
||||
var mappings = _findbytvdbIdCache.Find(tvdbId.ToString());
|
||||
if (_findByTvdbIdCache.Count == 0)
|
||||
{
|
||||
RefreshCache();
|
||||
}
|
||||
|
||||
var mappings = _findByTvdbIdCache.Find(tvdbId.ToString());
|
||||
|
||||
if (mappings == null)
|
||||
{
|
||||
|
@ -82,7 +87,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
|||
|
||||
public Nullable<Int32> GetSeasonNumber(string title)
|
||||
{
|
||||
var mapping = _gettvdbIdCache.Find(title.CleanSeriesTitle());
|
||||
var mapping = FindTvdbId(title);
|
||||
|
||||
if (mapping == null)
|
||||
return null;
|
||||
|
@ -126,21 +131,31 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
|||
RefreshCache();
|
||||
}
|
||||
|
||||
private SceneMapping FindTvdbId(string title)
|
||||
{
|
||||
if (_getTvdbIdCache.Count == 0)
|
||||
{
|
||||
RefreshCache();
|
||||
}
|
||||
|
||||
return _getTvdbIdCache.Find(title.CleanSeriesTitle());
|
||||
}
|
||||
|
||||
private void RefreshCache()
|
||||
{
|
||||
var mappings = _repository.All().ToList();
|
||||
|
||||
_gettvdbIdCache.Clear();
|
||||
_findbytvdbIdCache.Clear();
|
||||
_getTvdbIdCache.Clear();
|
||||
_findByTvdbIdCache.Clear();
|
||||
|
||||
foreach (var sceneMapping in mappings)
|
||||
{
|
||||
_gettvdbIdCache.Set(sceneMapping.ParseTerm.CleanSeriesTitle(), sceneMapping);
|
||||
_getTvdbIdCache.Set(sceneMapping.ParseTerm.CleanSeriesTitle(), sceneMapping);
|
||||
}
|
||||
|
||||
foreach (var sceneMapping in mappings.GroupBy(x => x.TvdbId))
|
||||
{
|
||||
_findbytvdbIdCache.Set(sceneMapping.Key.ToString(), sceneMapping.ToList());
|
||||
_findByTvdbIdCache.Set(sceneMapping.Key.ToString(), sceneMapping.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue