From df6c89ea234526a61df65ccf344ac52d34b3c97a Mon Sep 17 00:00:00 2001
From: Qstick <qstick@gmail.com>
Date: Fri, 11 Aug 2023 22:32:54 -0500
Subject: [PATCH] New: Improve performance of DeleteBadMediaCovers housekeeper

---
 .../Housekeepers}/DeleteBadMediaCovers.cs      | 18 +++++++++---------
 .../Housekeepers/DeleteBadMediaCovers.cs       |  8 ++++----
 2 files changed, 13 insertions(+), 13 deletions(-)
 rename src/NzbDrone.Core.Test/{HealthCheck/Checks => Housekeeping/Housekeepers}/DeleteBadMediaCovers.cs (92%)

diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs
similarity index 92%
rename from src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs
rename to src/NzbDrone.Core.Test/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs
index 62c058a56..32aa132df 100644
--- a/src/NzbDrone.Core.Test/HealthCheck/Checks/DeleteBadMediaCovers.cs
+++ b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs
@@ -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);
diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs
index 55fcb7485..2a5655768 100644
--- a/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs
+++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/DeleteBadMediaCovers.cs
@@ -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);