New: Faster processing of special releases
This commit is contained in:
parent
5a79b8502e
commit
9abdaca079
|
@ -49,5 +49,53 @@ namespace NzbDrone.Core.Test.TvTests.SeriesRepositoryTests
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenSeries()
|
||||||
|
{
|
||||||
|
var series = Builder<Series>.CreateListOfSize(2)
|
||||||
|
.TheFirst(1)
|
||||||
|
.With(x => x.CleanTitle = "crown")
|
||||||
|
.TheNext(1)
|
||||||
|
.With(x => x.CleanTitle = "crownextralong")
|
||||||
|
.BuildList();
|
||||||
|
|
||||||
|
Subject.InsertMany(series);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("crow")]
|
||||||
|
[TestCase("rownc")]
|
||||||
|
public void should_find_no_inexact_matches(string cleanTitle)
|
||||||
|
{
|
||||||
|
GivenSeries();
|
||||||
|
|
||||||
|
var found = Subject.FindByTitleInexact(cleanTitle);
|
||||||
|
found.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TestCase("crowna")]
|
||||||
|
[TestCase("acrown")]
|
||||||
|
[TestCase("acrowna")]
|
||||||
|
public void should_find_one_inexact_match(string cleanTitle)
|
||||||
|
{
|
||||||
|
GivenSeries();
|
||||||
|
|
||||||
|
var found = Subject.FindByTitleInexact(cleanTitle);
|
||||||
|
found.Should().HaveCount(1);
|
||||||
|
found.First().CleanTitle.Should().Be("crown");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("crownextralong")]
|
||||||
|
[TestCase("crownextralonga")]
|
||||||
|
[TestCase("acrownextralong")]
|
||||||
|
[TestCase("acrownextralonga")]
|
||||||
|
public void should_find_two_inexact_matches(string cleanTitle)
|
||||||
|
{
|
||||||
|
GivenSeries();
|
||||||
|
|
||||||
|
var found = Subject.FindByTitleInexact(cleanTitle);
|
||||||
|
found.Should().HaveCount(2);
|
||||||
|
found.Select(x => x.CleanTitle).Should().BeEquivalentTo(new [] {"crown", "crownextralong"});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
@ -10,6 +11,7 @@ namespace NzbDrone.Core.Tv
|
||||||
bool SeriesPathExists(string path);
|
bool SeriesPathExists(string path);
|
||||||
Series FindByTitle(string cleanTitle);
|
Series FindByTitle(string cleanTitle);
|
||||||
Series FindByTitle(string cleanTitle, int year);
|
Series FindByTitle(string cleanTitle, int year);
|
||||||
|
List<Series> FindByTitleInexact(string cleanTitle);
|
||||||
Series FindByTvdbId(int tvdbId);
|
Series FindByTvdbId(int tvdbId);
|
||||||
Series FindByTvRageId(int tvRageId);
|
Series FindByTvRageId(int tvRageId);
|
||||||
Series FindByPath(string path);
|
Series FindByPath(string path);
|
||||||
|
@ -17,9 +19,12 @@ namespace NzbDrone.Core.Tv
|
||||||
|
|
||||||
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
||||||
{
|
{
|
||||||
|
protected IMainDatabase _database;
|
||||||
|
|
||||||
public SeriesRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
public SeriesRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||||
: base(database, eventAggregator)
|
: base(database, eventAggregator)
|
||||||
{
|
{
|
||||||
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SeriesPathExists(string path)
|
public bool SeriesPathExists(string path)
|
||||||
|
@ -44,6 +49,14 @@ namespace NzbDrone.Core.Tv
|
||||||
.SingleOrDefault();
|
.SingleOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Series> FindByTitleInexact(string cleanTitle)
|
||||||
|
{
|
||||||
|
var mapper = _database.GetDataMapper();
|
||||||
|
mapper.AddParameter("CleanTitle", cleanTitle);
|
||||||
|
|
||||||
|
return mapper.Query<Series>().Where($"instr(@CleanTitle, [t0].[CleanTitle])");
|
||||||
|
}
|
||||||
|
|
||||||
public Series FindByTvdbId(int tvdbId)
|
public Series FindByTvdbId(int tvdbId)
|
||||||
{
|
{
|
||||||
return Query.Where(s => s.TvdbId == tvdbId).SingleOrDefault();
|
return Query.Where(s => s.TvdbId == tvdbId).SingleOrDefault();
|
||||||
|
|
|
@ -97,7 +97,7 @@ namespace NzbDrone.Core.Tv
|
||||||
{
|
{
|
||||||
// find any series clean title within the provided release title
|
// find any series clean title within the provided release title
|
||||||
string cleanTitle = title.CleanSeriesTitle();
|
string cleanTitle = title.CleanSeriesTitle();
|
||||||
var list = _seriesRepository.All().Where(s => cleanTitle.Contains(s.CleanTitle)).ToList();
|
var list = _seriesRepository.FindByTitleInexact(cleanTitle);
|
||||||
if (!list.Any())
|
if (!list.Any())
|
||||||
{
|
{
|
||||||
// no series matched
|
// no series matched
|
||||||
|
|
Loading…
Reference in New Issue