From 88cd6a3213d5d560d5e2e4df8e94b03fa50180af Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 1 Jun 2013 12:39:30 -0700 Subject: [PATCH] removed join from EpisodesBetweenDates, should be join in memoery in the API --- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 - .../ProviderTests/MisnamedProviderTest.cs | 260 ------------------ NzbDrone.Core/NzbDrone.Core.csproj | 3 - NzbDrone.Core/Providers/MisnamedProvider.cs | 61 ---- NzbDrone.Core/Tv/Episode.cs | 16 -- NzbDrone.Core/Tv/EpisodeRepository.cs | 16 +- NzbDrone.Core/Tv/EpisodeService.cs | 15 +- 7 files changed, 8 insertions(+), 364 deletions(-) delete mode 100644 NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs delete mode 100644 NzbDrone.Core/Providers/MisnamedProvider.cs diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index d4a7c2088..d8bd1b5d5 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -187,7 +187,6 @@ - diff --git a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs deleted file mode 100644 index 614410643..000000000 --- a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs +++ /dev/null @@ -1,260 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using FizzWare.NBuilder; -using FluentAssertions; -using Moq; -using NUnit.Framework; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Organizer; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Providers; - -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.ProviderTests -{ - [TestFixture] - public class MisnamedProviderTest : CoreTest - { - [Test] - public void no_misnamed_files() - { - - var series = Builder.CreateNew() - .With(s => s.Title = "SeriesTitle") - .Build(); - - var episodeFiles = Builder.CreateListOfSize(2) - .TheFirst(1) - .With(f => f.Id = 1) - .With(f => f.Path = @"C:\Test\Title1.avi") - .TheNext(1) - .With(f => f.Id = 2) - .With(f => f.Path = @"C:\Test\Title2.avi") - .Build().ToList(); - - var episodes = Builder.CreateListOfSize(2) - .All() - .With(e => e.Series = series) - .TheFirst(1) - .With(e => e.EpisodeFile = episodeFiles[0]) - .TheNext(1) - .With(e => e.EpisodeFile = episodeFiles[1]) - .Build().ToList(); - - - - Mocker.GetMock() - .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[0] }, It.IsAny(), episodeFiles[0])) - .Returns("Title1"); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[1] }, It.IsAny(), episodeFiles[1])) - .Returns("Title2"); - - - var totalItems = 0; - var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems); - - - misnamedEpisodes.Should().HaveCount(0); - } - - [Test] - public void all_misnamed_files() - { - - var series = Builder.CreateNew() - .With(s => s.Title = "SeriesTitle") - .Build(); - - var episodeFiles = Builder.CreateListOfSize(2) - .TheFirst(1) - .With(f => f.Id = 1) - .With(f => f.Path = @"C:\Test\Title1.avi") - .TheNext(1) - .With(f => f.Id = 2) - .With(f => f.Path = @"C:\Test\Title2.avi") - .Build(); - - var episodes = Builder.CreateListOfSize(2) - .All() - .With(e => e.Series = series) - .TheFirst(1) - .With(e => e.EpisodeFile = episodeFiles[0]) - .TheNext(1) - .With(e => e.EpisodeFile = episodeFiles[1]) - .Build().ToList(); - - - - Mocker.GetMock() - .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[0] }, It.IsAny(), episodeFiles[0])) - .Returns("New Title 1"); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[1] }, It.IsAny(), episodeFiles[1])) - .Returns("New Title 2"); - - - var totalItems = 0; - var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems); - - - misnamedEpisodes.Should().HaveCount(2); - } - - [Test] - public void one_misnamed_file() - { - - var series = Builder.CreateNew() - .With(s => s.Title = "SeriesTitle") - .Build(); - - var episodeFiles = Builder.CreateListOfSize(2) - .TheFirst(1) - .With(f => f.Id = 1) - .With(f => f.Path = @"C:\Test\Title1.avi") - .TheNext(1) - .With(f => f.Id = 2) - .With(f => f.Path = @"C:\Test\Title2.avi") - .Build(); - - var episodes = Builder.CreateListOfSize(2) - .All() - .With(e => e.Series = series) - .TheFirst(1) - .With(e => e.EpisodeFile = episodeFiles[0]) - .TheNext(1) - .With(e => e.EpisodeFile = episodeFiles[1]) - .Build().ToList(); - - - - Mocker.GetMock() - .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[0] }, It.IsAny(), episodeFiles[0])) - .Returns("New Title 1"); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[1] }, It.IsAny(), episodeFiles[1])) - .Returns("Title2"); - - - var totalItems = 0; - var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems); - - - misnamedEpisodes.Should().HaveCount(1); - misnamedEpisodes[0].CurrentName.Should().Be("Title1"); - misnamedEpisodes[0].ProperName.Should().Be("New Title 1"); - } - - [Test] - [Ignore] - public void misnamed_multi_episode_file() - { - - var series = Builder.CreateNew() - .With(s => s.Title = "SeriesTitle") - .Build(); - - var episodeFiles = Builder.CreateListOfSize(2) - .TheFirst(1) - .With(f => f.Id = 1) - .With(f => f.Path = @"C:\Test\Title1.avi") - .TheNext(1) - .With(f => f.Id = 2) - .With(f => f.Path = @"C:\Test\Title2.avi") - .Build().ToList(); - - var episodes = Builder.CreateListOfSize(3) - .All() - .With(e => e.Series = series) - .TheFirst(2) - .With(e => e.EpisodeFile = episodeFiles[0]) - .TheNext(1) - .With(e => e.EpisodeFile = episodeFiles[1]) - .Build().ToList(); - - - - Mocker.GetMock() - .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[0], episodes[1] }, It.IsAny(), episodeFiles[0])) - .Returns("New Title 1"); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[2] }, It.IsAny(), episodeFiles[1])) - .Returns("Title2"); - - - var totalItems = 0; - var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems); - - - misnamedEpisodes.Should().HaveCount(1); - misnamedEpisodes[0].CurrentName.Should().Be("Title1"); - misnamedEpisodes[0].ProperName.Should().Be("New Title 1"); - } - - [Test] - [Ignore] - public void no_misnamed_multi_episode_file() - { - - var series = Builder.CreateNew() - .With(s => s.Title = "SeriesTitle") - .Build(); - - var episodeFiles = Builder.CreateListOfSize(2) - .TheFirst(1) - .With(f => f.Id = 1) - .With(f => f.Path = @"C:\Test\Title1.avi") - .TheNext(1) - .With(f => f.Id = 2) - .With(f => f.Path = @"C:\Test\Title2.avi") - .Build().ToList(); - - var episodes = Builder.CreateListOfSize(3) - .All() - .With(e => e.Series = series) - .TheFirst(2) - .With(e => e.EpisodeFile = episodeFiles[0]) - .TheNext(1) - .With(e => e.EpisodeFile = episodeFiles[1]) - .Build().ToList(); - - - - Mocker.GetMock() - .Setup(c => c.EpisodesWithFiles()).Returns(episodes); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[0], episodes[1] }, It.IsAny(), episodeFiles[0])) - .Returns("Title1"); - - Mocker.GetMock() - .Setup(c => c.BuildFilename(new List { episodes[2] }, It.IsAny(), episodeFiles[1])) - .Returns("Title2"); - - - var totalItems = 0; - var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems); - - - misnamedEpisodes.Should().HaveCount(0); - } - } -} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 532e2c566..33039d2ce 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -464,9 +464,6 @@ Code - - Code - Code diff --git a/NzbDrone.Core/Providers/MisnamedProvider.cs b/NzbDrone.Core/Providers/MisnamedProvider.cs deleted file mode 100644 index 267ee76d7..000000000 --- a/NzbDrone.Core/Providers/MisnamedProvider.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using NzbDrone.Core.Organizer; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model; - - -namespace NzbDrone.Core.Providers -{ - public class MisnamedProvider - { - private readonly IEpisodeService _episodeService; - private readonly IBuildFileNames _buildFileNames; - - - public MisnamedProvider(IEpisodeService episodeService, IBuildFileNames buildFileNames) - { - _episodeService = episodeService; - _buildFileNames = buildFileNames; - } - - public virtual List MisnamedFiles(int pageNumber, int pageSize, out int totalItems) - { - var misnamedFiles = new List(); - - var episodesWithFiles = _episodeService.EpisodesWithFiles().GroupBy(e => e.EpisodeFileId).ToList(); - totalItems = episodesWithFiles.Count(); - - var misnamedFilesSelect = episodesWithFiles.AsParallel().Where( - w => - w.First().EpisodeFile.Value.Path != - _buildFileNames.BuildFilename(w.Select(e => e).ToList(), w.First().Series, w.First().EpisodeFile)).Skip(Math.Max(pageSize * (pageNumber - 1), 0)).Take(pageSize); - - //Process the episodes - misnamedFilesSelect.AsParallel().ForAll(f => - { - var episodes = f.Select(e => e).ToList(); - var firstEpisode = episodes[0]; - var properName = _buildFileNames.BuildFilename(episodes, firstEpisode.Series, - firstEpisode.EpisodeFile); - - var currentName = Path.GetFileNameWithoutExtension(firstEpisode.EpisodeFile.Value.Path); - - if (properName != currentName) - { - misnamedFiles.Add(new MisnamedEpisodeModel - { - CurrentName = currentName, - EpisodeFileId = firstEpisode.EpisodeFileId, - ProperName = properName, - SeriesTitle = firstEpisode.Series.Value.Title - }); - } - }); - - return misnamedFiles.OrderBy(e => e.SeriesTitle).ToList(); - } - } -} diff --git a/NzbDrone.Core/Tv/Episode.cs b/NzbDrone.Core/Tv/Episode.cs index 3a0f5e13a..d00b926c5 100644 --- a/NzbDrone.Core/Tv/Episode.cs +++ b/NzbDrone.Core/Tv/Episode.cs @@ -23,25 +23,9 @@ namespace NzbDrone.Core.Tv public int SceneSeasonNumber { get; set; } public int SceneEpisodeNumber { get; set; } - public bool HasFile - { - get { return EpisodeFileId != 0; } - } - public String SeriesTitle { get; private set; } - public LazyLoaded Series { get; set; } - public LazyLoaded EpisodeFile { get; set; } - public override string ToString() - { - string seriesTitle = Series == null ? "[NULL]" : Series.Value.Title; - - if (Series != null && Series.Value.SeriesType == SeriesTypes.Daily && AirDate.HasValue) - return string.Format("{0} - {1:yyyy-MM-dd}", seriesTitle, AirDate.Value); - - return string.Format("{0} - S{1:00}E{2:00}", seriesTitle, SeasonNumber, EpisodeNumber); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index a621543f2..e066f97ed 100644 --- a/NzbDrone.Core/Tv/EpisodeRepository.cs +++ b/NzbDrone.Core/Tv/EpisodeRepository.cs @@ -83,13 +83,12 @@ namespace NzbDrone.Core.Tv startingSeasonNumber = 0; } - var pagingQuery = Query.Join(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id) - .Where(e => e.EpisodeFileId == 0) - .AndWhere(e => e.SeasonNumber >= startingSeasonNumber) - .AndWhere(e => e.AirDate <= currentTime) - .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) - .Skip(pagingSpec.PagingOffset()) - .Take(pagingSpec.PageSize); + var pagingQuery = Query.Where(e => e.EpisodeFileId == 0) + .AndWhere(e => e.SeasonNumber >= startingSeasonNumber) + .AndWhere(e => e.AirDate <= currentTime) + .OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection()) + .Skip(pagingSpec.PagingOffset()) + .Take(pagingSpec.PageSize); pagingSpec.Records = pagingQuery.ToList(); @@ -116,8 +115,7 @@ namespace NzbDrone.Core.Tv public List EpisodesBetweenDates(DateTime startDate, DateTime endDate) { - return Query.Join(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id) - .Where(e => e.AirDate >= startDate) + return Query.Where(e => e.AirDate >= startDate) .AndWhere(e => e.AirDate <= endDate).ToList(); } diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index e287a0edb..1cd41c89c 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -180,7 +180,6 @@ namespace NzbDrone.Core.Tv } episodeToUpdate.SeriesId = series.Id; - episodeToUpdate.Series = series; episodeToUpdate.TvDbEpisodeId = episode.TvDbEpisodeId; episodeToUpdate.EpisodeNumber = episode.EpisodeNumber; episodeToUpdate.SeasonNumber = episode.SeasonNumber; @@ -208,7 +207,7 @@ namespace NzbDrone.Core.Tv int episodeCount = 0; foreach (var episode in group.OrderBy(e => e.SeasonNumber).ThenBy(e => e.EpisodeNumber)) { - episode.AirDate = episode.AirDate.Value.AddMinutes(episode.Series.Value.Runtime * episodeCount); + episode.AirDate = episode.AirDate.Value.AddMinutes(series.Runtime * episodeCount); episodeCount++; } } @@ -326,17 +325,5 @@ namespace NzbDrone.Core.Tv logger.Trace("Deleted episodes that no longer exist in TVDB for {0}", series.Id); } - - private List LinkSeriesToEpisodes(List episodes) - { - var series = _seriesService.GetSeriesInList(episodes.Select(e => e.SeriesId).Distinct()); - - episodes.ForEach(e => - { - e.Series = series.SingleOrDefault(s => s.Id == e.SeriesId); - }); - - return episodes; - } } } \ No newline at end of file