mirror of https://github.com/Radarr/Radarr
Fixed: Housekeeper doesn't remove collections that have MovieMeta from lists
This commit is contained in:
parent
69fcd8ec94
commit
aa0104b6bc
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_delete_unorphaned_collection_items()
|
||||
public void should_delete_orphaned_collection_with_meta_but_no_movie_items()
|
||||
{
|
||||
var collection = Builder<MovieCollection>.CreateNew()
|
||||
.With(h => h.Id = 3)
|
||||
|
@ -40,6 +40,27 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
|||
|
||||
Db.Insert(movie);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_delete_unorphaned_collection()
|
||||
{
|
||||
var collection = Builder<MovieCollection>.CreateNew()
|
||||
.With(h => h.Id = 3)
|
||||
.With(h => h.TmdbId = 123456)
|
||||
.With(h => h.Title = "Some Credit")
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(collection);
|
||||
|
||||
var movieMeta = Builder<MovieMetadata>.CreateNew().With(m => m.CollectionTmdbId = collection.TmdbId).BuildNew();
|
||||
Db.Insert(movieMeta);
|
||||
|
||||
var movie = Builder<Movie>.CreateNew().With(m => m.MovieMetadataId = movieMeta.Id).BuildNew();
|
||||
Db.Insert(movie);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM ""Collections""
|
||||
WHERE ""TmdbId"" IN (
|
||||
SELECT ""Collections"".""TmdbId"" FROM ""Collections""
|
||||
LEFT OUTER JOIN ""MovieMetadata""
|
||||
ON ""Collections"".""TmdbId"" = ""MovieMetadata"".""CollectionTmdbId""
|
||||
WHERE ""MovieMetadata"".""Id"" IS NULL)");
|
||||
mapper.Execute(@"DELETE FROM ""Collections"" WHERE ""TmdbId"" IN (SELECT ""X"".""TmdbId"" FROM (SELECT ""Collections"".""TmdbId"", COUNT(""Movies"".""Id"") as ""MovieCount"" FROM ""Collections""
|
||||
LEFT OUTER JOIN ""MovieMetadata"" ON ""Collections"".""TmdbId"" = ""MovieMetadata"".""CollectionTmdbId""
|
||||
LEFT OUTER JOIN ""Movies"" ON ""Movies"".""MovieMetadataId"" = ""MovieMetadata"".""Id""
|
||||
GROUP BY ""Collections"".""Id"") AS ""X"" WHERE ""X"".""MovieCount"" = 0)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue