mirror of
https://github.com/Sonarr/Sonarr
synced 2025-02-24 15:11:27 +00:00
New: Faster processing of special releases
This commit is contained in:
parent
5a79b8502e
commit
9abdaca079
3 changed files with 63 additions and 2 deletions
|
@ -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 NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
@ -10,6 +11,7 @@ namespace NzbDrone.Core.Tv
|
|||
bool SeriesPathExists(string path);
|
||||
Series FindByTitle(string cleanTitle);
|
||||
Series FindByTitle(string cleanTitle, int year);
|
||||
List<Series> FindByTitleInexact(string cleanTitle);
|
||||
Series FindByTvdbId(int tvdbId);
|
||||
Series FindByTvRageId(int tvRageId);
|
||||
Series FindByPath(string path);
|
||||
|
@ -17,9 +19,12 @@ namespace NzbDrone.Core.Tv
|
|||
|
||||
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
||||
{
|
||||
protected IMainDatabase _database;
|
||||
|
||||
public SeriesRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public bool SeriesPathExists(string path)
|
||||
|
@ -44,6 +49,14 @@ namespace NzbDrone.Core.Tv
|
|||
.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)
|
||||
{
|
||||
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
|
||||
string cleanTitle = title.CleanSeriesTitle();
|
||||
var list = _seriesRepository.All().Where(s => cleanTitle.Contains(s.CleanTitle)).ToList();
|
||||
var list = _seriesRepository.FindByTitleInexact(cleanTitle);
|
||||
if (!list.Any())
|
||||
{
|
||||
// no series matched
|
||||
|
|
Loading…
Reference in a new issue