New: Improve performance of DeleteBadMediaCovers housekeeper

pull/5559/head
Qstick 1 year ago
parent d8f314ff0e
commit df6c89ea23

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

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

Loading…
Cancel
Save