From d7aaa1cdc2fc48f841866b20d7e4c70c42536c4c Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 9 Nov 2023 14:58:31 +0200 Subject: [PATCH] Fixed: Cleanup orphaned movies --- .../Housekeepers/CleanupOrphanedMovies.cs | 25 +++++++++++++++++++ .../Movies/ShouldRefreshMovie.cs | 7 +++++- src/Radarr.Api.V3/Movies/MovieController.cs | 10 +++++++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMovies.cs diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMovies.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMovies.cs new file mode 100644 index 000000000..4360ecd8a --- /dev/null +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMovies.cs @@ -0,0 +1,25 @@ +using Dapper; +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Core.Housekeeping.Housekeepers +{ + public class CleanupOrphanedMovies : IHousekeepingTask + { + private readonly IMainDatabase _database; + + public CleanupOrphanedMovies(IMainDatabase database) + { + _database = database; + } + + public void Clean() + { + using var mapper = _database.OpenConnection(); + mapper.Execute(@"DELETE FROM ""Movies"" + WHERE ""Id"" IN ( + SELECT ""Movies"".""Id"" FROM ""Movies"" + LEFT OUTER JOIN ""MovieMetadata"" ON ""Movies"".""MovieMetadataId"" = ""MovieMetadata"".""Id"" + WHERE ""MovieMetadata"".""Id"" IS NULL)"); + } + } +} diff --git a/src/NzbDrone.Core/Movies/ShouldRefreshMovie.cs b/src/NzbDrone.Core/Movies/ShouldRefreshMovie.cs index 86ad65651..f041b0384 100644 --- a/src/NzbDrone.Core/Movies/ShouldRefreshMovie.cs +++ b/src/NzbDrone.Core/Movies/ShouldRefreshMovie.cs @@ -19,7 +19,12 @@ public ShouldRefreshMovie(Logger logger) public bool ShouldRefresh(MovieMetadata movie) { - // return false; + if (movie == null) + { + _logger.Warn("Movie metadata does not exist, should not be refreshed."); + return false; + } + if (movie.LastInfoSync < DateTime.UtcNow.AddDays(-180)) { _logger.Trace("Movie {0} last updated more than 180 days ago, should refresh.", movie.Title); diff --git a/src/Radarr.Api.V3/Movies/MovieController.cs b/src/Radarr.Api.V3/Movies/MovieController.cs index 19ba771b2..1e577fd34 100644 --- a/src/Radarr.Api.V3/Movies/MovieController.cs +++ b/src/Radarr.Api.V3/Movies/MovieController.cs @@ -214,7 +214,15 @@ private MovieTranslation GetTranslationFromDict(Dictionary