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,45 +117,43 @@ 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) ect = nextRssSync.Value;
{ }
ect = nextRssSync.Value; else
} {
else ect = ect.AddMinutes(_configService.RssSyncInterval);
{ }
ect = ect.AddMinutes(_configService.RssSyncInterval);
} var queue = new Queue.Queue
{
var queue = new Queue.Queue Id = GetQueueId(pendingRelease, pendingRelease.RemoteMovie.Movie),
{ Series = null,
Id = GetQueueId(pendingRelease, pendingRelease.RemoteMovie.Movie), Episode = null,
Series = null, Movie = pendingRelease.RemoteMovie.Movie,
Episode = null, Quality = pendingRelease.RemoteMovie.ParsedMovieInfo?.Quality ?? new QualityModel(),
Movie = pendingRelease.RemoteMovie.Movie, Title = pendingRelease.Title,
Quality = pendingRelease.RemoteMovie.ParsedMovieInfo.Quality, Size = pendingRelease.RemoteMovie.Release.Size,
Title = pendingRelease.Title, Sizeleft = pendingRelease.RemoteMovie.Release.Size,
Size = pendingRelease.RemoteMovie.Release.Size, RemoteMovie = pendingRelease.RemoteMovie,
Sizeleft = pendingRelease.RemoteMovie.Release.Size, Timeleft = ect.Subtract(DateTime.UtcNow),
RemoteMovie = pendingRelease.RemoteMovie, EstimatedCompletionTime = ect,
Timeleft = ect.Subtract(DateTime.UtcNow), Status = "Pending",
EstimatedCompletionTime = ect, Protocol = pendingRelease.RemoteMovie.Release.DownloadProtocol
Status = "Pending", };
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