New: Improve performance of DeleteBadMediaCovers housekeeper

This commit is contained in:
Qstick 2023-08-11 22:32:54 -05:00
parent d8f314ff0e
commit df6c89ea23
2 changed files with 13 additions and 13 deletions

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -14,31 +14,31 @@ using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.HealthCheck.Checks
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
{
[TestFixture]
public class DeleteBadMediaCoversFixture : CoreTest<DeleteBadMediaCovers>
{
private List<MetadataFile> _metadata;
private List<Series> _series;
private Dictionary<int, string> _series;
[SetUp]
public void Setup()
{
_series = Builder<Series>.CreateListOfSize(1)
.All()
.With(c => c.Path = "C:\\TV\\".AsOsAgnostic())
.Build().ToList();
_series = new Dictionary<int, string>
{
{ 1, "C:\\TV\\".AsOsAgnostic() }
};
_metadata = Builder<MetadataFile>.CreateListOfSize(1)
.Build().ToList();
Mocker.GetMock<ISeriesService>()
.Setup(c => c.GetAllSeries())
.Setup(c => c.GetAllSeriesPaths())
.Returns(_series);
Mocker.GetMock<IMetadataFileService>()
.Setup(c => c.GetFilesBySeries(_series.First().Id))
.Setup(c => c.GetFilesBySeries(_series.First().Key))
.Returns(_metadata);
Mocker.GetMock<IConfigService>().SetupGet(c => c.CleanupMetadataImages).Returns(true);

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using NLog;
@ -37,18 +37,18 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
return;
}
var series = _seriesService.GetAllSeries();
var series = _seriesService.GetAllSeriesPaths();
foreach (var show in series)
{
var images = _metaFileService.GetFilesBySeries(show.Id)
var images = _metaFileService.GetFilesBySeries(show.Key)
.Where(c => c.LastUpdated > new DateTime(2014, 12, 27) && c.RelativePath.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase));
foreach (var image in images)
{
try
{
var path = Path.Combine(show.Path, image.RelativePath);
var path = Path.Combine(show.Value, image.RelativePath);
if (!IsValid(path))
{
_logger.Debug("Deleting invalid image file " + path);