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
{
[TestFixture]
public class CleanupOrphanedEpisodeFilesFixture : DbTest<CleanupOrphanedEpisodeFiles, EpisodeFile>
public class CleanupOrphanedEpisodeFilesFixture : DbTest<CleanupOrphanedEpisodeFiles, MovieFile>
{
[Test]
public void should_delete_orphaned_episode_files()
{
var episodeFile = Builder<EpisodeFile>.CreateNew()
var episodeFile = Builder<MovieFile>.CreateNew()
.With(h => h.Quality = new QualityModel())
.BuildNew();
@ -28,22 +28,22 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
[Test]
public void should_not_delete_unorphaned_episode_files()
{
var episodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
var episodeFiles = Builder<MovieFile>.CreateListOfSize(2)
.All()
.With(h => h.Quality = new QualityModel())
.BuildListOfNew();
Db.InsertMany(episodeFiles);
var episode = Builder<Episode>.CreateNew()
.With(e => e.EpisodeFileId = episodeFiles.First().Id)
var episode = Builder<Movie>.CreateNew()
.With(e => e.MovieFileId = episodeFiles.First().Id)
.BuildNew();
Db.Insert(episode);
Subject.Clean();
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 episode in pendingRelease.RemoteEpisode.Episodes)
//{
var ect = pendingRelease.Release.PublishDate.AddMinutes(GetDelay(pendingRelease.RemoteMovie));
if (ect < nextRssSync.Value)
{
ect = nextRssSync.Value;
}
else
{
ect = ect.AddMinutes(_configService.RssSyncInterval);
}
var queue = new Queue.Queue
{
Id = GetQueueId(pendingRelease, pendingRelease.RemoteMovie.Movie),
Series = null,
Episode = null,
Movie = pendingRelease.RemoteMovie.Movie,
Quality = pendingRelease.RemoteMovie.ParsedMovieInfo.Quality,
Title = pendingRelease.Title,
Size = pendingRelease.RemoteMovie.Release.Size,
Sizeleft = pendingRelease.RemoteMovie.Release.Size,
RemoteMovie = pendingRelease.RemoteMovie,
Timeleft = ect.Subtract(DateTime.UtcNow),
EstimatedCompletionTime = ect,
Status = "Pending",
Protocol = pendingRelease.RemoteMovie.Release.DownloadProtocol
};
queued.Add(queue);
//}
var ect = pendingRelease.Release.PublishDate.AddMinutes(GetDelay(pendingRelease.RemoteMovie));
if (ect < nextRssSync.Value)
{
ect = nextRssSync.Value;
}
else
{
ect = ect.AddMinutes(_configService.RssSyncInterval);
}
var queue = new Queue.Queue
{
Id = GetQueueId(pendingRelease, pendingRelease.RemoteMovie.Movie),
Series = null,
Episode = null,
Movie = pendingRelease.RemoteMovie.Movie,
Quality = pendingRelease.RemoteMovie.ParsedMovieInfo?.Quality ?? new QualityModel(),
Title = pendingRelease.Title,
Size = pendingRelease.RemoteMovie.Release.Size,
Sizeleft = pendingRelease.RemoteMovie.Release.Size,
RemoteMovie = pendingRelease.RemoteMovie,
Timeleft = ect.Subtract(DateTime.UtcNow),
EstimatedCompletionTime = ect,
Status = "Pending",
Protocol = pendingRelease.RemoteMovie.Release.DownloadProtocol
};
queued.Add(queue);
}
//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))
.First();
});
@ -254,12 +252,12 @@ namespace NzbDrone.Core.Download.Pending
return new[] { delay, minimumAge }.Max();
}
private void RemoveGrabbed(RemoteMovie remoteEpisode)
private void RemoveGrabbed(RemoteMovie remoteMovie)
{
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();
if (existingReports.Empty())
@ -267,11 +265,11 @@ namespace NzbDrone.Core.Download.Pending
return;
}
var profile = remoteEpisode.Movie.Profile.Value;
var profile = remoteMovie.Movie.Profile.Value;
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);
//Only remove lower/equal quality pending releases

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

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

@ -6,21 +6,21 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
{
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()
{
var series = _seriesRepository.All().ToList();
var movies = _movieRepository.All().ToList();
series.ForEach(s =>
movies.ForEach(m =>
{
s.CleanTitle = s.CleanTitle.CleanSeriesTitle();
_seriesRepository.Update(s);
m.CleanTitle = m.CleanTitle.CleanSeriesTitle();
_movieRepository.Update(m);
});
}
}

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

Loading…
Cancel
Save