Changed: Don't return unmapped folders on rootfolder API call. Massively improves loading time. (#3116)

Justin Kromlinger 6 years ago committed by Leonardo Galli
parent 95fdf38662
commit 623da76d16

@ -52,7 +52,7 @@ namespace NzbDrone.Api.RootFolders
private List<RootFolderResource> GetRootFolders() private List<RootFolderResource> GetRootFolders()
{ {
return _rootFolderService.AllWithUnmappedFolders().ToResource(); return _rootFolderService.AllWithSpace().ToResource();
} }
private void DeleteFolder(int id) private void DeleteFolder(int id)

@ -15,6 +15,7 @@ namespace NzbDrone.Core.RootFolders
{ {
List<RootFolder> All(); List<RootFolder> All();
List<RootFolder> AllWithUnmappedFolders(); List<RootFolder> AllWithUnmappedFolders();
List<RootFolder> AllWithSpace();
RootFolder Add(RootFolder rootDir); RootFolder Add(RootFolder rootDir);
void Remove(int id); void Remove(int id);
RootFolder Get(int id); RootFolder Get(int id);
@ -62,6 +63,31 @@ namespace NzbDrone.Core.RootFolders
return rootFolders; return rootFolders;
} }
public List<RootFolder> AllWithSpace()
{
var rootFolders = _rootFolderRepository.All().ToList();
rootFolders.ForEach(folder =>
{
try
{
if (folder.Path.IsPathValid() && _diskProvider.FolderExists(folder.Path))
{
folder.FreeSpace = _diskProvider.GetAvailableSpace(folder.Path);
folder.TotalSpace = _diskProvider.GetTotalSize(folder.Path);
}
}
//We don't want an exception to prevent the root folders from loading in the UI, so they can still be deleted
catch (Exception ex)
{
folder.FreeSpace = 0;
_logger.Error(ex, "Unable to get free space for root folder {0}", folder.Path);
}
});
return rootFolders;
}
public List<RootFolder> AllWithUnmappedFolders() public List<RootFolder> AllWithUnmappedFolders()
{ {
var rootFolders = _rootFolderRepository.All().ToList(); var rootFolders = _rootFolderRepository.All().ToList();

Loading…
Cancel
Save