mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-18 16:29:41 +02:00
Fixed: Speed up Unmapped Folder fetch for large number of root folders
This commit is contained in:
parent
646b86f8c9
commit
95918c4053
@ -45,6 +45,10 @@ private void WithNonExistingFolder()
|
||||
[TestCase("//server//folder")]
|
||||
public void should_be_able_to_add_root_dir(string path)
|
||||
{
|
||||
Mocker.GetMock<IMovieRepository>()
|
||||
.Setup(s => s.AllMoviePaths())
|
||||
.Returns(new List<string>());
|
||||
|
||||
var root = new RootFolder { Path = path.AsOsAgnostic() };
|
||||
|
||||
Subject.Add(root);
|
||||
@ -134,9 +138,9 @@ public void should_get_root_folder_with_subfolders_excluding_special_sub_folders
|
||||
.Setup(s => s.Get(It.IsAny<int>()))
|
||||
.Returns(rootFolder);
|
||||
|
||||
Mocker.GetMock<IMovieService>()
|
||||
.Setup(s => s.GetAllMovies())
|
||||
.Returns(new List<Movie>());
|
||||
Mocker.GetMock<IMovieRepository>()
|
||||
.Setup(s => s.AllMoviePaths())
|
||||
.Returns(new List<string>());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetDirectories(rootFolder.Path))
|
||||
|
@ -67,13 +67,15 @@ public List<RootFolder> AllWithUnmappedFolders()
|
||||
{
|
||||
var rootFolders = _rootFolderRepository.All().ToList();
|
||||
|
||||
var moviePaths = _movieRepository.AllMoviePaths().ToList();
|
||||
|
||||
rootFolders.ForEach(folder =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (folder.Path.IsPathValid())
|
||||
{
|
||||
GetDetails(folder, true);
|
||||
GetDetails(folder, moviePaths, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +116,9 @@ public RootFolder Add(RootFolder rootFolder)
|
||||
|
||||
_rootFolderRepository.Insert(rootFolder);
|
||||
|
||||
GetDetails(rootFolder, true);
|
||||
var moviePaths = _movieRepository.AllMoviePaths().ToList();
|
||||
|
||||
GetDetails(rootFolder, moviePaths, true);
|
||||
|
||||
return rootFolder;
|
||||
}
|
||||
@ -124,7 +128,7 @@ public void Remove(int id)
|
||||
_rootFolderRepository.Delete(id);
|
||||
}
|
||||
|
||||
private List<UnmappedFolder> GetUnmappedFolders(string path)
|
||||
private List<UnmappedFolder> GetUnmappedFolders(string path, List<string> moviePaths)
|
||||
{
|
||||
_logger.Debug("Generating list of unmapped folders");
|
||||
|
||||
@ -134,7 +138,6 @@ private List<UnmappedFolder> GetUnmappedFolders(string path)
|
||||
}
|
||||
|
||||
var results = new List<UnmappedFolder>();
|
||||
var movies = _movieRepository.All().ToList();
|
||||
|
||||
if (!_diskProvider.FolderExists(path))
|
||||
{
|
||||
@ -143,7 +146,7 @@ private List<UnmappedFolder> GetUnmappedFolders(string path)
|
||||
}
|
||||
|
||||
var possibleMovieFolders = _diskProvider.GetDirectories(path).ToList();
|
||||
var unmappedFolders = possibleMovieFolders.Except(movies.Select(s => s.Path), PathEqualityComparer.Instance).ToList();
|
||||
var unmappedFolders = possibleMovieFolders.Except(moviePaths.Select(s => s), PathEqualityComparer.Instance).ToList();
|
||||
|
||||
foreach (string unmappedFolder in unmappedFolders)
|
||||
{
|
||||
@ -164,7 +167,9 @@ private List<UnmappedFolder> GetUnmappedFolders(string path)
|
||||
public RootFolder Get(int id, bool timeout)
|
||||
{
|
||||
var rootFolder = _rootFolderRepository.Get(id);
|
||||
GetDetails(rootFolder, timeout);
|
||||
var moviePaths = _movieRepository.AllMoviePaths().ToList();
|
||||
|
||||
GetDetails(rootFolder, moviePaths, timeout);
|
||||
|
||||
return rootFolder;
|
||||
}
|
||||
@ -183,7 +188,7 @@ public string GetBestRootFolderPath(string path)
|
||||
return possibleRootFolder.Path;
|
||||
}
|
||||
|
||||
private void GetDetails(RootFolder rootFolder, bool timeout)
|
||||
private void GetDetails(RootFolder rootFolder, List<string> moviePaths, bool timeout)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
@ -192,7 +197,7 @@ private void GetDetails(RootFolder rootFolder, bool timeout)
|
||||
rootFolder.Accessible = true;
|
||||
rootFolder.FreeSpace = _diskProvider.GetAvailableSpace(rootFolder.Path);
|
||||
rootFolder.TotalSpace = _diskProvider.GetTotalSize(rootFolder.Path);
|
||||
rootFolder.UnmappedFolders = GetUnmappedFolders(rootFolder.Path);
|
||||
rootFolder.UnmappedFolders = GetUnmappedFolders(rootFolder.Path, moviePaths);
|
||||
}
|
||||
}).Wait(timeout ? 5000 : -1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user