From 6947e6e34cf1bf7bf07790dfe809aa6becf8e464 Mon Sep 17 00:00:00 2001 From: ta264 Date: Wed, 1 Dec 2021 21:56:48 +0000 Subject: [PATCH] Fixed: Speed up initial author load --- .../RootFolders/RootFolderService.cs | 17 +++++++++-- src/Readarr.Api.V1/Author/AuthorController.cs | 30 +++++-------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index b215dc159..1ab06bef0 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -27,6 +27,7 @@ public interface IRootFolderService List AllForTag(int tagId); RootFolder GetBestRootFolder(string path); string GetBestRootFolderPath(string path); + string GetBestRootFolderPath(string path, List allRootFolders); } public class RootFolderService : IRootFolderService, IHandle> @@ -145,14 +146,26 @@ public List AllForTag(int tagId) 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 allRootFolders) + { + return allRootFolders.Where(r => PathEqualityComparer.Instance.Equals(r.Path, path) || r.Path.IsParentPath(path)) .OrderByDescending(r => r.Path.Length) .FirstOrDefault(); } public string GetBestRootFolderPath(string path) { - var possibleRootFolder = GetBestRootFolder(path); + var folders = All(); + return GetBestRootFolderPath(path, folders); + } + + public string GetBestRootFolderPath(string path, List allRootFolders) + { + var possibleRootFolder = GetBestRootFolder(path, allRootFolders); if (possibleRootFolder == null) { diff --git a/src/Readarr.Api.V1/Author/AuthorController.cs b/src/Readarr.Api.V1/Author/AuthorController.cs index 5eaa6e98f..84a7cf8f0 100644 --- a/src/Readarr.Api.V1/Author/AuthorController.cs +++ b/src/Readarr.Api.V1/Author/AuthorController.cs @@ -112,7 +112,6 @@ private AuthorResource GetAuthorResource(NzbDrone.Core.Books.Author author) FetchAndLinkAuthorStatistics(resource); LinkNextPreviousBooks(resource); - //PopulateAlternateTitles(resource); LinkRootFolderPath(resource); return resource; @@ -127,10 +126,8 @@ public List AllAuthors() MapCoversToLocal(authorResources.ToArray()); LinkNextPreviousBooks(authorResources.ToArray()); LinkAuthorStatistics(authorResources, authorStats); + LinkRootFolderPath(authorResources.ToArray()); - authorResources.ForEach(LinkRootFolderPath); - - //PopulateAlternateTitles(seriesResources); return authorResources; } @@ -223,25 +220,14 @@ private void LinkAuthorStatistics(AuthorResource resource, AuthorStatistics auth resource.Statistics = authorStatistics.ToResource(); } - //private void PopulateAlternateTitles(List resources) - //{ - // foreach (var resource in resources) - // { - // 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(); - //} - private void LinkRootFolderPath(AuthorResource resource) + private void LinkRootFolderPath(params AuthorResource[] authors) { - resource.RootFolderPath = _rootFolderService.GetBestRootFolderPath(resource.Path); + var rootFolders = _rootFolderService.All(); + + foreach (var author in authors) + { + author.RootFolderPath = _rootFolderService.GetBestRootFolderPath(author.Path, rootFolders); + } } [NonAction]