1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-19 17:32:38 +01:00

Fixed: Cleanup orphaned movies

This commit is contained in:
Bogdan 2023-11-09 14:58:31 +02:00
parent 263534717d
commit d7aaa1cdc2
3 changed files with 40 additions and 2 deletions

View File

@ -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)");
}
}
}

View File

@ -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);

View File

@ -214,7 +214,15 @@ private MovieTranslation GetTranslationFromDict(Dictionary<int, MovieTranslation
};
}
translations.TryGetValue(movie.Id, out var translation);
if (!translations.TryGetValue(movie.Id, out var translation))
{
translation = new MovieTranslation
{
Title = movie.Title,
Language = Language.English
};
}
return translation;
}