Fix pending release service, HDBits, also the release deduper. Clean up housekeeping (#1211)

* Fix HDbits

* Fix pending release service, also fix the deduper

* Clean up the cleanup'er (housekeeping)

* Revert "Clean up the cleanup'er (housekeeping)"

This reverts commit c03c13d9241a0f59f118cd9ffccba5646a3f52ca.

* Housekeeping updates, without breaking tests

* Fix last test
pull/2/head
Devin Buhl 8 years ago committed by GitHub
parent 59c07cc5f3
commit c593f4250d

@ -11,12 +11,12 @@ using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
{ {
[TestFixture] [TestFixture]
public class CleanupOrphanedEpisodeFilesFixture : DbTest<CleanupOrphanedEpisodeFiles, EpisodeFile> public class CleanupOrphanedEpisodeFilesFixture : DbTest<CleanupOrphanedEpisodeFiles, MovieFile>
{ {
[Test] [Test]
public void should_delete_orphaned_episode_files() public void should_delete_orphaned_episode_files()
{ {
var episodeFile = Builder<EpisodeFile>.CreateNew() var episodeFile = Builder<MovieFile>.CreateNew()
.With(h => h.Quality = new QualityModel()) .With(h => h.Quality = new QualityModel())
.BuildNew(); .BuildNew();
@ -28,22 +28,22 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
[Test] [Test]
public void should_not_delete_unorphaned_episode_files() public void should_not_delete_unorphaned_episode_files()
{ {
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2) var episodeFiles = Builder<MovieFile>.CreateListOfSize(2)
.All() .All()
.With(h => h.Quality = new QualityModel()) .With(h => h.Quality = new QualityModel())
.BuildListOfNew(); .BuildListOfNew();
Db.InsertMany(episodeFiles); Db.InsertMany(episodeFiles);
var episode = Builder<Episode>.CreateNew() var episode = Builder<Movie>.CreateNew()
.With(e => e.EpisodeFileId = episodeFiles.First().Id) .With(e => e.MovieFileId = episodeFiles.First().Id)
.BuildNew(); .BuildNew();
Db.Insert(episode); Db.Insert(episode);
Subject.Clean(); Subject.Clean();
AllStoredModels.Should().HaveCount(1); AllStoredModels.Should().HaveCount(1);
Db.All<Episode>().Should().Contain(e => e.EpisodeFileId == AllStoredModels.First().Id); Db.All<Movie>().Should().Contain(e => e.MovieFileId == AllStoredModels.First().Id);
} }
} }
} }

@ -117,8 +117,6 @@ namespace NzbDrone.Core.Download.Pending
foreach (var pendingRelease in GetPendingReleases()) foreach (var pendingRelease in GetPendingReleases())
{ {
//foreach (var episode in pendingRelease.RemoteEpisode.Episodes)
//{
var ect = pendingRelease.Release.PublishDate.AddMinutes(GetDelay(pendingRelease.RemoteMovie)); var ect = pendingRelease.Release.PublishDate.AddMinutes(GetDelay(pendingRelease.RemoteMovie));
if (ect < nextRssSync.Value) if (ect < nextRssSync.Value)
@ -136,7 +134,7 @@ namespace NzbDrone.Core.Download.Pending
Series = null, Series = null,
Episode = null, Episode = null,
Movie = pendingRelease.RemoteMovie.Movie, Movie = pendingRelease.RemoteMovie.Movie,
Quality = pendingRelease.RemoteMovie.ParsedMovieInfo.Quality, Quality = pendingRelease.RemoteMovie.ParsedMovieInfo?.Quality ?? new QualityModel(),
Title = pendingRelease.Title, Title = pendingRelease.Title,
Size = pendingRelease.RemoteMovie.Release.Size, Size = pendingRelease.RemoteMovie.Release.Size,
Sizeleft = pendingRelease.RemoteMovie.Release.Size, Sizeleft = pendingRelease.RemoteMovie.Release.Size,
@ -146,16 +144,16 @@ namespace NzbDrone.Core.Download.Pending
Status = "Pending", Status = "Pending",
Protocol = pendingRelease.RemoteMovie.Release.DownloadProtocol Protocol = pendingRelease.RemoteMovie.Release.DownloadProtocol
}; };
queued.Add(queue); queued.Add(queue);
//}
} }
//Return best quality release for each episode //Return best quality release for each episode
var deduped = queued.GroupBy(q => q.Episode.Id).Select(g => var deduped = queued.GroupBy(q => q.Movie.Id).Select(g =>
{ {
var series = g.First().Series; var movies = g.First().Movie;
return g.OrderByDescending(e => e.Quality, new QualityModelComparer(series.Profile)) return g.OrderByDescending(e => e.Quality, new QualityModelComparer(movies.Profile))
.ThenBy(q => PrioritizeDownloadProtocol(q.Movie, q.Protocol)) .ThenBy(q => PrioritizeDownloadProtocol(q.Movie, q.Protocol))
.First(); .First();
}); });
@ -254,12 +252,12 @@ namespace NzbDrone.Core.Download.Pending
return new[] { delay, minimumAge }.Max(); return new[] { delay, minimumAge }.Max();
} }
private void RemoveGrabbed(RemoteMovie remoteEpisode) private void RemoveGrabbed(RemoteMovie remoteMovie)
{ {
var pendingReleases = GetPendingReleases(); var pendingReleases = GetPendingReleases();
var existingReports = pendingReleases.Where(r => r.RemoteMovie.Movie.Id == remoteEpisode.Movie.Id) var existingReports = pendingReleases.Where(r => r.RemoteMovie.Movie.Id == remoteMovie.Movie.Id)
.ToList(); .ToList();
if (existingReports.Empty()) if (existingReports.Empty())
@ -267,11 +265,11 @@ namespace NzbDrone.Core.Download.Pending
return; return;
} }
var profile = remoteEpisode.Movie.Profile.Value; var profile = remoteMovie.Movie.Profile.Value;
foreach (var existingReport in existingReports) foreach (var existingReport in existingReports)
{ {
var compare = new QualityModelComparer(profile).Compare(remoteEpisode.ParsedMovieInfo.Quality, var compare = new QualityModelComparer(profile).Compare(remoteMovie.ParsedMovieInfo.Quality,
existingReport.RemoteMovie.ParsedMovieInfo.Quality); existingReport.RemoteMovie.ParsedMovieInfo.Quality);
//Only remove lower/equal quality pending releases //Only remove lower/equal quality pending releases

@ -15,12 +15,12 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{ {
var mapper = _database.GetDataMapper(); var mapper = _database.GetDataMapper();
mapper.ExecuteNonQuery(@"DELETE FROM EpisodeFiles mapper.ExecuteNonQuery(@"DELETE FROM MovieFiles
WHERE Id IN ( WHERE Id IN (
SELECT EpisodeFiles.Id FROM EpisodeFiles SELECT MovieFiles.Id FROM MovieFiles
LEFT OUTER JOIN Episodes LEFT OUTER JOIN Movies
ON EpisodeFiles.Id = Episodes.EpisodeFileId ON MovieFiles.Id = Movies.MovieFileId
WHERE Episodes.Id IS NULL)"); WHERE Movies.Id IS NULL)");
} }
} }
} }

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{ {
var mapper = _database.GetDataMapper(); var mapper = _database.GetDataMapper();
var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "Restrictions" } var usedTags = new[] { "Movies", "Series", "Notifications", "DelayProfiles", "Restrictions" }
.SelectMany(v => GetUsedTags(v, mapper)) .SelectMany(v => GetUsedTags(v, mapper))
.Distinct() .Distinct()
.ToArray(); .ToArray();

@ -6,21 +6,21 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{ {
public class UpdateCleanTitleForSeries : IHousekeepingTask public class UpdateCleanTitleForSeries : IHousekeepingTask
{ {
private readonly ISeriesRepository _seriesRepository; private readonly IMovieRepository _movieRepository;
public UpdateCleanTitleForSeries(ISeriesRepository seriesRepository) public UpdateCleanTitleForSeries(IMovieRepository movieRepository)
{ {
_seriesRepository = seriesRepository; _movieRepository = movieRepository;
} }
public void Clean() public void Clean()
{ {
var series = _seriesRepository.All().ToList(); var movies = _movieRepository.All().ToList();
series.ForEach(s => movies.ForEach(m =>
{ {
s.CleanTitle = s.CleanTitle.CleanSeriesTitle(); m.CleanTitle = m.CleanTitle.CleanSeriesTitle();
_seriesRepository.Update(s); _movieRepository.Update(m);
}); });
} }
} }

@ -65,7 +65,7 @@ namespace NzbDrone.Core.Indexers.HDBits
Peers = result.Leechers + result.Seeders, Peers = result.Leechers + result.Seeders,
PublishDate = result.Added.ToUniversalTime(), PublishDate = result.Added.ToUniversalTime(),
Internal = internalRelease, Internal = internalRelease,
ImdbId = result.ImdbInfo.Id ImdbId = result.ImdbInfo?.Id ?? 0
}); });
} }

Loading…
Cancel
Save