From 5704adfbc5e575a348e8e1bea4b2c742439b9526 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 18 Jan 2024 18:51:43 -0600 Subject: [PATCH] New: Improve All Authors call by using dictionary for stats iteration (cherry picked from commit e792db4d3355fedd3ea9e35b3f5e1e30394d9ee3) Closes #3230 --- src/Readarr.Api.V1/Author/AuthorController.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Readarr.Api.V1/Author/AuthorController.cs b/src/Readarr.Api.V1/Author/AuthorController.cs index 37711d948..e39cb53ca 100644 --- a/src/Readarr.Api.V1/Author/AuthorController.cs +++ b/src/Readarr.Api.V1/Author/AuthorController.cs @@ -127,7 +127,7 @@ namespace Readarr.Api.V1.Author MapCoversToLocal(authorResources.ToArray()); LinkNextPreviousBooks(authorResources.ToArray()); - LinkAuthorStatistics(authorResources, authorStats); + LinkAuthorStatistics(authorResources, authorStats.ToDictionary(x => x.AuthorId)); LinkRootFolderPath(authorResources.ToArray()); return authorResources; @@ -200,17 +200,14 @@ namespace Readarr.Api.V1.Author LinkAuthorStatistics(resource, _authorStatisticsService.AuthorStatistics(resource.Id)); } - private void LinkAuthorStatistics(List resources, List authorStatistics) + private void LinkAuthorStatistics(List resources, Dictionary authorStatistics) { foreach (var author in resources) { - var stats = authorStatistics.SingleOrDefault(ss => ss.AuthorId == author.Id); - if (stats == null) + if (authorStatistics.TryGetValue(author.Id, out var stats)) { - continue; + LinkAuthorStatistics(author, stats); } - - LinkAuthorStatistics(author, stats); } }