path performance optimization
This commit is contained in:
parent
0503d7eea6
commit
91d64f0b6a
|
@ -6,6 +6,13 @@ namespace NzbDrone.Common
|
|||
{
|
||||
public class PathEqualityComparer : IEqualityComparer<String>
|
||||
{
|
||||
public static readonly PathEqualityComparer Instance = new PathEqualityComparer();
|
||||
|
||||
private PathEqualityComparer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Equals(string x, string y)
|
||||
{
|
||||
return x.PathEquals(y);
|
||||
|
|
|
@ -40,10 +40,12 @@ namespace NzbDrone.Common
|
|||
{
|
||||
if (OsInfo.IsLinux)
|
||||
{
|
||||
if (firstPath.Equals(secondPath)) return true;
|
||||
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath());
|
||||
}
|
||||
|
||||
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.InvariantCultureIgnoreCase);
|
||||
if (firstPath.Equals(secondPath, StringComparison.OrdinalIgnoreCase)) return true;
|
||||
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static readonly Regex WindowsPathWithDriveRegex = new Regex(@"^[a-zA-Z]:\\", RegexOptions.Compiled);
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
|||
imported.Add(new ImportDecision(localEpisode));
|
||||
|
||||
Mocker.GetMock<IMakeImportDecision>()
|
||||
.Setup(s => s.GetImportDecisions(It.IsAny<IEnumerable<String>>(), It.IsAny<Series>(), true, null))
|
||||
.Setup(s => s.GetImportDecisions(It.IsAny<List<String>>(), It.IsAny<Series>(), true, null))
|
||||
.Returns(imported);
|
||||
|
||||
Mocker.GetMock<IImportApprovedEpisodes>()
|
||||
|
|
|
@ -56,14 +56,16 @@ namespace NzbDrone.Core.MediaFiles
|
|||
{
|
||||
_logger.Debug("Creating missing series folder: {0}", series.Path);
|
||||
_diskProvider.CreateFolder(series.Path);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug("Series folder doesn't exist: {0}", series.Path);
|
||||
}
|
||||
|
||||
_logger.Debug("Series folder doesn't exist: {0}", series.Path);
|
||||
return;
|
||||
}
|
||||
|
||||
var mediaFileList = GetVideoFiles(series.Path);
|
||||
var mediaFileList = GetVideoFiles(series.Path).ToList();
|
||||
|
||||
var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, series, false);
|
||||
_importApprovedEpisodes.Import(decisions);
|
||||
|
|
|
@ -133,7 +133,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
private List<ImportDecision> ProcessFiles(Series series, QualityModel quality, params string[] videoFiles)
|
||||
{
|
||||
var decisions = _importDecisionMaker.GetImportDecisions(videoFiles, series, true, quality);
|
||||
var decisions = _importDecisionMaker.GetImportDecisions(videoFiles.ToList(), series, true, quality);
|
||||
return _importApprovedEpisodes.Import(decisions, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,10 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
|
||||
public List<ImportDecision> Import(List<ImportDecision> decisions, bool newDownload = false)
|
||||
{
|
||||
var qualifiedImports = GetQualifiedImports(decisions);
|
||||
var qualifiedImports = decisions.Where(c => c.Approved)
|
||||
.OrderByDescending(c => c.LocalEpisode.Quality)
|
||||
.ThenByDescending(c => c.LocalEpisode.Size);
|
||||
|
||||
var imported = new List<ImportDecision>();
|
||||
|
||||
foreach (var importDecision in qualifiedImports.OrderByDescending(e => e.LocalEpisode.Size))
|
||||
|
@ -48,9 +51,9 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
|
||||
try
|
||||
{
|
||||
//check if already imported
|
||||
if (imported.SelectMany(r => r.LocalEpisode.Episodes)
|
||||
.Select(e => e.Id)
|
||||
.ToList()
|
||||
.Intersect(localEpisode.Episodes.Select(e => e.Id))
|
||||
.Any())
|
||||
{
|
||||
|
@ -91,13 +94,5 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
|
||||
return imported;
|
||||
}
|
||||
|
||||
private List<ImportDecision> GetQualifiedImports(List<ImportDecision> decisions)
|
||||
{
|
||||
return decisions.Where(c => c.Approved)
|
||||
.OrderByDescending(c => c.LocalEpisode.Quality)
|
||||
.ThenByDescending(c => c.LocalEpisode.Size)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
{
|
||||
public interface IMakeImportDecision
|
||||
{
|
||||
List<ImportDecision> GetImportDecisions(IEnumerable<String> videoFiles, Series series, bool sceneSource, QualityModel quality = null);
|
||||
List<ImportDecision> GetImportDecisions(List<String> videoFiles, Series series, bool sceneSource, QualityModel quality = null);
|
||||
}
|
||||
|
||||
public class ImportDecisionMaker : IMakeImportDecision
|
||||
|
@ -38,11 +38,11 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<ImportDecision> GetImportDecisions(IEnumerable<string> videoFiles, Series series, bool sceneSource, QualityModel quality = null)
|
||||
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, bool sceneSource, QualityModel quality = null)
|
||||
{
|
||||
var newFiles = _mediaFileService.FilterExistingFiles(videoFiles.ToList(), series.Id);
|
||||
|
||||
_logger.Debug("Analysing {0}/{1} files.", newFiles.Count, videoFiles.Count());
|
||||
_logger.Debug("Analyzing {0}/{1} files.", newFiles.Count, videoFiles.Count());
|
||||
|
||||
return GetDecisions(newFiles, series, sceneSource, quality).ToList();
|
||||
}
|
||||
|
|
|
@ -65,11 +65,11 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
public List<string> FilterExistingFiles(List<string> files, int seriesId)
|
||||
{
|
||||
var seriesFiles = GetFilesBySeries(seriesId).Select(f => f.Path.CleanFilePath()).ToList();
|
||||
var seriesFiles = GetFilesBySeries(seriesId).Select(f => f.Path).ToList();
|
||||
|
||||
if (!seriesFiles.Any()) return files;
|
||||
|
||||
return files.Select(f => f.CleanFilePath()).Except(seriesFiles, new PathEqualityComparer()).ToList();
|
||||
return files.Except(seriesFiles, PathEqualityComparer.Instance).ToList();
|
||||
}
|
||||
|
||||
public EpisodeFile Get(int id)
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace NzbDrone.Core.RootFolders
|
|||
}
|
||||
|
||||
var seriesFolders = _diskProvider.GetDirectories(path).ToList();
|
||||
var unmappedFolders = seriesFolders.Except(series.Select(s => s.Path), new PathEqualityComparer()).ToList();
|
||||
var unmappedFolders = seriesFolders.Except(series.Select(s => s.Path), PathEqualityComparer.Instance).ToList();
|
||||
|
||||
foreach (string unmappedFolder in unmappedFolders)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue