Fixed: Speed up initial author load

pull/1343/head
ta264 3 years ago
parent c51ae664aa
commit 6947e6e34c

@ -27,6 +27,7 @@ namespace NzbDrone.Core.RootFolders
List<RootFolder> AllForTag(int tagId); List<RootFolder> AllForTag(int tagId);
RootFolder GetBestRootFolder(string path); RootFolder GetBestRootFolder(string path);
string GetBestRootFolderPath(string path); string GetBestRootFolderPath(string path);
string GetBestRootFolderPath(string path, List<RootFolder> allRootFolders);
} }
public class RootFolderService : IRootFolderService, IHandle<ModelEvent<RemotePathMapping>> public class RootFolderService : IRootFolderService, IHandle<ModelEvent<RemotePathMapping>>
@ -145,14 +146,26 @@ namespace NzbDrone.Core.RootFolders
public RootFolder GetBestRootFolder(string path) public RootFolder GetBestRootFolder(string path)
{ {
return All().Where(r => PathEqualityComparer.Instance.Equals(r.Path, path) || r.Path.IsParentPath(path)) var folders = All();
return GetBestRootFolder(path, folders);
}
public RootFolder GetBestRootFolder(string path, List<RootFolder> allRootFolders)
{
return allRootFolders.Where(r => PathEqualityComparer.Instance.Equals(r.Path, path) || r.Path.IsParentPath(path))
.OrderByDescending(r => r.Path.Length) .OrderByDescending(r => r.Path.Length)
.FirstOrDefault(); .FirstOrDefault();
} }
public string GetBestRootFolderPath(string path) public string GetBestRootFolderPath(string path)
{ {
var possibleRootFolder = GetBestRootFolder(path); var folders = All();
return GetBestRootFolderPath(path, folders);
}
public string GetBestRootFolderPath(string path, List<RootFolder> allRootFolders)
{
var possibleRootFolder = GetBestRootFolder(path, allRootFolders);
if (possibleRootFolder == null) if (possibleRootFolder == null)
{ {

@ -112,7 +112,6 @@ namespace Readarr.Api.V1.Author
FetchAndLinkAuthorStatistics(resource); FetchAndLinkAuthorStatistics(resource);
LinkNextPreviousBooks(resource); LinkNextPreviousBooks(resource);
//PopulateAlternateTitles(resource);
LinkRootFolderPath(resource); LinkRootFolderPath(resource);
return resource; return resource;
@ -127,10 +126,8 @@ namespace Readarr.Api.V1.Author
MapCoversToLocal(authorResources.ToArray()); MapCoversToLocal(authorResources.ToArray());
LinkNextPreviousBooks(authorResources.ToArray()); LinkNextPreviousBooks(authorResources.ToArray());
LinkAuthorStatistics(authorResources, authorStats); LinkAuthorStatistics(authorResources, authorStats);
LinkRootFolderPath(authorResources.ToArray());
authorResources.ForEach(LinkRootFolderPath);
//PopulateAlternateTitles(seriesResources);
return authorResources; return authorResources;
} }
@ -223,25 +220,14 @@ namespace Readarr.Api.V1.Author
resource.Statistics = authorStatistics.ToResource(); resource.Statistics = authorStatistics.ToResource();
} }
//private void PopulateAlternateTitles(List<AuthorResource> resources) private void LinkRootFolderPath(params AuthorResource[] authors)
//{ {
// foreach (var resource in resources) var rootFolders = _rootFolderService.All();
// {
// PopulateAlternateTitles(resource);
// }
//}
//private void PopulateAlternateTitles(AuthorResource resource)
//{
// var mappings = _sceneMappingService.FindByTvdbId(resource.TvdbId);
// if (mappings == null) return;
// resource.AlternateTitles = mappings.Select(v => new AlternateTitleResource { Title = v.Title, SeasonNumber = v.SeasonNumber, SceneSeasonNumber = v.SceneSeasonNumber }).ToList(); foreach (var author in authors)
//}
private void LinkRootFolderPath(AuthorResource resource)
{ {
resource.RootFolderPath = _rootFolderService.GetBestRootFolderPath(resource.Path); author.RootFolderPath = _rootFolderService.GetBestRootFolderPath(author.Path, rootFolders);
}
} }
[NonAction] [NonAction]

Loading…
Cancel
Save