Speedier unmapped folders lookup.

pull/6/head
Mark McDowall 11 years ago
parent f9437baf80
commit 0c2a1c60b1

@ -5,9 +5,9 @@ namespace NzbDrone.Api.RootFolders
{
public class RootFolderModule : NzbDroneRestModule<RootFolderResource>
{
private readonly RootFolderService _rootFolderService;
private readonly IRootFolderService _rootFolderService;
public RootFolderModule(RootFolderService rootFolderService)
public RootFolderModule(IRootFolderService rootFolderService)
{
_rootFolderService = rootFolderService;

@ -91,6 +91,7 @@
<Compile Include="Exceptions\NzbDroneException.cs" />
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
<Compile Include="Instrumentation\ExceptronTarget.cs" />
<Compile Include="PathEqualityComparer.cs" />
<Compile Include="TPL\LimitedConcurrencyLevelTaskScheduler.cs" />
<Compile Include="Security\IgnoreCertErrorPolicy.cs" />
<Compile Include="StringExtensions.cs" />

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Common
{
public class PathEqualityComparer : IEqualityComparer<String>
{
public bool Equals(string x, string y)
{
return x.PathEquals(y);
}
public int GetHashCode(string obj)
{
return obj.CleanFilePath().GetHashCode();
}
}
}

@ -35,11 +35,12 @@ namespace NzbDrone.Common
return info.FullName.TrimEnd('/').Trim('\\', ' ');
}
public static bool PathEquals(this string firstPath, string secondPath)
{
Ensure.That(() => firstPath).IsValidPath();
Ensure.That(() => secondPath).IsValidPath();
if (OsInfo.IsLinux)
{
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath());
}
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.InvariantCultureIgnoreCase);
}

@ -1,4 +1,5 @@
using System.Linq;
using System.Diagnostics;
using System.Linq;
using System;
using System.Collections.Generic;
using System.IO;
@ -40,14 +41,14 @@ namespace NzbDrone.Core.RootFolders
_configService = configService;
}
public virtual List<RootFolder> All()
public List<RootFolder> All()
{
var rootFolders = _rootFolderRepository.All().ToList();
return rootFolders;
}
public virtual List<RootFolder> AllWithUnmappedFolders()
public List<RootFolder> AllWithUnmappedFolders()
{
var rootFolders = _rootFolderRepository.All().ToList();
@ -63,7 +64,7 @@ namespace NzbDrone.Core.RootFolders
return rootFolders;
}
public virtual RootFolder Add(RootFolder rootFolder)
public RootFolder Add(RootFolder rootFolder)
{
var all = All();
@ -87,12 +88,12 @@ namespace NzbDrone.Core.RootFolders
return rootFolder;
}
public virtual void Remove(int id)
public void Remove(int id)
{
_rootFolderRepository.Delete(id);
}
public virtual List<UnmappedFolder> GetUnmappedFolders(string path)
public List<UnmappedFolder> GetUnmappedFolders(string path)
{
Logger.Debug("Generating list of unmapped folders");
if (String.IsNullOrEmpty(path))
@ -107,13 +108,13 @@ namespace NzbDrone.Core.RootFolders
return results;
}
foreach (string seriesFolder in _diskProvider.GetDirectories(path))
var seriesFolders = _diskProvider.GetDirectories(path).ToList();
var unmappedFolders = seriesFolders.Except(series.Select(s => s.Path), new PathEqualityComparer()).ToList();
foreach (string unmappedFolder in unmappedFolders)
{
if (!series.Any(s => s.Path.PathEquals(seriesFolder)))
{
var di = new DirectoryInfo(seriesFolder.Normalize());
results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName });
}
var di = new DirectoryInfo(unmappedFolder.Normalize());
results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName });
}
if (Path.GetPathRoot(path).Equals(path, StringComparison.InvariantCultureIgnoreCase))
@ -126,7 +127,7 @@ namespace NzbDrone.Core.RootFolders
return results;
}
public virtual Dictionary<string, long> FreeSpaceOnDrives()
public Dictionary<string, long> FreeSpaceOnDrives()
{
var freeSpace = new Dictionary<string, long>();

Loading…
Cancel
Save