1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

path performance optimization

This commit is contained in:
kayone 2013-11-30 16:33:59 -08:00
parent 0503d7eea6
commit 91d64f0b6a
9 changed files with 28 additions and 22 deletions

View File

@ -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);

View File

@ -40,10 +40,12 @@ public static bool PathEquals(this string firstPath, string secondPath)
{
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);

View File

@ -124,7 +124,7 @@ public void should_delete_folder_if_files_were_imported()
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>()

View File

@ -56,14 +56,16 @@ private void Scan(Series series)
{
_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);

View File

@ -133,7 +133,7 @@ private void ProcessVideoFile(string videoFile)
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);
}

View File

@ -38,7 +38,10 @@ public ImportApprovedEpisodes(IUpgradeMediaFiles episodeFileUpgrader,
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 @@ public List<ImportDecision> Import(List<ImportDecision> decisions, bool newDownl
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 @@ public List<ImportDecision> Import(List<ImportDecision> decisions, bool newDownl
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();
}
}
}

View File

@ -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 @@ public ImportDecisionMaker(IEnumerable<IRejectWithReason> specifications,
_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();
}

View File

@ -65,11 +65,11 @@ public List<EpisodeFile> GetFilesBySeason(int seriesId, int seasonNumber)
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)

View File

@ -111,7 +111,7 @@ public List<UnmappedFolder> GetUnmappedFolders(string path)
}
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)
{