removed join from EpisodesBetweenDates, should be join in memoery in the API

This commit is contained in:
kay.one 2013-06-01 12:39:30 -07:00
parent 0c63e5ad81
commit 88cd6a3213
7 changed files with 8 additions and 364 deletions

View File

@ -187,7 +187,6 @@
<Compile Include="HelperTests\SortHelperTest.cs" />
<Compile Include="DecisionEngineTests\AcceptableSizeSpecificationFixture.cs" />
<Compile Include="Qualities\QualitySizeServiceFixture.cs" />
<Compile Include="ProviderTests\MisnamedProviderTest.cs" />
<Compile Include="ProviderTests\EventClientProviderTest.cs" />
<Compile Include="ProviderTests\XbmcProviderTest.cs" />
<Compile Include="TvTests\EpisodeProviderTests\EpisodeProviderTest_GetEpisodesByParseResult.cs" />

View File

@ -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<MisnamedProvider>
{
[Test]
public void no_misnamed_files()
{
var series = Builder<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.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<Episode>.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<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), episodeFiles[0]))
.Returns("Title1");
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), 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<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.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<Episode>.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<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), episodeFiles[0]))
.Returns("New Title 1");
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), 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<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.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<Episode>.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<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0] }, It.IsAny<Series>(), episodeFiles[0]))
.Returns("New Title 1");
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[1] }, It.IsAny<Series>(), 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<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.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<Episode>.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<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0], episodes[1] }, It.IsAny<Series>(), episodeFiles[0]))
.Returns("New Title 1");
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), 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<Series>.CreateNew()
.With(s => s.Title = "SeriesTitle")
.Build();
var episodeFiles = Builder<EpisodeFile>.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<Episode>.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<IEpisodeService>()
.Setup(c => c.EpisodesWithFiles()).Returns(episodes);
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[0], episodes[1] }, It.IsAny<Series>(), episodeFiles[0]))
.Returns("Title1");
Mocker.GetMock<IBuildFileNames>()
.Setup(c => c.BuildFilename(new List<Episode> { episodes[2] }, It.IsAny<Series>(), episodeFiles[1]))
.Returns("Title2");
var totalItems = 0;
var misnamedEpisodes = Subject.MisnamedFiles(1, 10, out totalItems);
misnamedEpisodes.Should().HaveCount(0);
}
}
}

View File

@ -464,9 +464,6 @@
<Compile Include="MediaFiles\MediaFileService.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\MisnamedProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\NotificationProvider.cs">
<SubType>Code</SubType>
</Compile>

View File

@ -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<MisnamedEpisodeModel> MisnamedFiles(int pageNumber, int pageSize, out int totalItems)
{
var misnamedFiles = new List<MisnamedEpisodeModel>();
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();
}
}
}

View File

@ -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> Series { get; set; }
public LazyLoaded<EpisodeFile> 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);
}
}
}

View File

@ -83,8 +83,7 @@ namespace NzbDrone.Core.Tv
startingSeasonNumber = 0;
}
var pagingQuery = Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
.Where(e => e.EpisodeFileId == 0)
var pagingQuery = Query.Where(e => e.EpisodeFileId == 0)
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
.AndWhere(e => e.AirDate <= currentTime)
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
@ -116,8 +115,7 @@ namespace NzbDrone.Core.Tv
public List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate)
{
return Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
.Where<Episode>(e => e.AirDate >= startDate)
return Query.Where<Episode>(e => e.AirDate >= startDate)
.AndWhere(e => e.AirDate <= endDate).ToList();
}

View File

@ -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<Episode> LinkSeriesToEpisodes(List<Episode> 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;
}
}
}