From 927ae86e4415455ca94cdabe0b3d93f1eaf33df1 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 17 Aug 2023 21:50:22 -0500 Subject: [PATCH] Fixed: Don't Clean if no lists synced Fixes #9011 --- .../ImportListSyncServiceFixture.cs | 28 ++++++++++++++++++- .../FetchAndParseImportListService.cs | 3 +- .../ImportLists/ImportListBase.cs | 1 + .../ImportLists/ImportListSyncService.cs | 5 ++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs b/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs index 7f2fbddab..95283449c 100644 --- a/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs +++ b/src/NzbDrone.Core.Test/ImportListTests/ImportListSyncServiceFixture.cs @@ -59,7 +59,8 @@ namespace NzbDrone.Core.Test.ImportList _importListFetch = new ImportListFetchResult { Movies = _list1Movies, - AnyFailure = false + AnyFailure = false, + SyncedLists = 1 }; _commandAll = new ImportListSyncCommand @@ -97,6 +98,11 @@ namespace NzbDrone.Core.Test.ImportList _importListFetch.AnyFailure = true; } + private void GivenNoListSync() + { + _importListFetch.SyncedLists = 0; + } + private void GivenCleanLevel(string cleanLevel) { Mocker.GetMock() @@ -145,6 +151,26 @@ namespace NzbDrone.Core.Test.ImportList .Verify(v => v.UpdateMovie(new List(), true), Times.Never()); } + [Test] + public void should_not_clean_library_or_process_movies_if_no_synced_lists() + { + _importListFetch.Movies.ForEach(m => m.ListId = 1); + GivenList(1, true); + GivenCleanLevel("logOnly"); + GivenNoListSync(); + + Subject.Execute(_commandAll); + + Mocker.GetMock() + .Verify(v => v.GetAllMovies(), Times.Never()); + + Mocker.GetMock() + .Verify(v => v.UpdateMovie(new List(), true), Times.Never()); + + Mocker.GetMock() + .Verify(v => v.GetAllExclusions(), Times.Never); + } + [Test] public void should_log_only_on_clean_library_if_config_value_logonly() { diff --git a/src/NzbDrone.Core/ImportLists/FetchAndParseImportListService.cs b/src/NzbDrone.Core/ImportLists/FetchAndParseImportListService.cs index d1325fa47..40dc132b3 100644 --- a/src/NzbDrone.Core/ImportLists/FetchAndParseImportListService.cs +++ b/src/NzbDrone.Core/ImportLists/FetchAndParseImportListService.cs @@ -113,6 +113,7 @@ namespace NzbDrone.Core.ImportLists } result.AnyFailure |= importListReports.AnyFailure; + result.SyncedLists++; _importListStatusService.UpdateListSyncStatus(importList.Definition.Id); } @@ -130,7 +131,7 @@ namespace NzbDrone.Core.ImportLists result.Movies = result.Movies.DistinctBy(r => new { r.TmdbId, r.ImdbId, r.Title }).ToList(); - _logger.Debug("Found {0} total reports from {1} lists", result.Movies.Count, importLists.Count); + _logger.Debug("Found {0} total reports from {1} lists", result.Movies.Count, result.SyncedLists); return result; } diff --git a/src/NzbDrone.Core/ImportLists/ImportListBase.cs b/src/NzbDrone.Core/ImportLists/ImportListBase.cs index eaa77abe6..e8c962317 100644 --- a/src/NzbDrone.Core/ImportLists/ImportListBase.cs +++ b/src/NzbDrone.Core/ImportLists/ImportListBase.cs @@ -19,6 +19,7 @@ namespace NzbDrone.Core.ImportLists public List Movies { get; set; } public bool AnyFailure { get; set; } + public int SyncedLists { get; set; } } public abstract class ImportListBase : IImportList diff --git a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs index 986f71ba6..9b98d28ba 100644 --- a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs +++ b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs @@ -60,6 +60,11 @@ namespace NzbDrone.Core.ImportLists return; } + if (result.SyncedLists == 0) + { + return; + } + if (!result.AnyFailure) { CleanLibrary();