From e792db4d3355fedd3ea9e35b3f5e1e30394d9ee3 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 18 Jan 2024 18:51:43 -0600 Subject: [PATCH] New: Improve All Series call by using dictionary for stats iteration --- src/Sonarr.Api.V3/Series/SeriesController.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Sonarr.Api.V3/Series/SeriesController.cs b/src/Sonarr.Api.V3/Series/SeriesController.cs index 1a920a6e0..14ee8f465 100644 --- a/src/Sonarr.Api.V3/Series/SeriesController.cs +++ b/src/Sonarr.Api.V3/Series/SeriesController.cs @@ -113,7 +113,7 @@ namespace Sonarr.Api.V3.Series } MapCoversToLocal(seriesResources.ToArray()); - LinkSeriesStatistics(seriesResources, seriesStats); + LinkSeriesStatistics(seriesResources, seriesStats.ToDictionary(x => x.SeriesId)); PopulateAlternateTitles(seriesResources); seriesResources.ForEach(LinkRootFolderPath); @@ -229,17 +229,14 @@ namespace Sonarr.Api.V3.Series LinkSeriesStatistics(resource, _seriesStatisticsService.SeriesStatistics(resource.Id)); } - private void LinkSeriesStatistics(List resources, List seriesStatistics) + private void LinkSeriesStatistics(List resources, Dictionary seriesStatistics) { foreach (var series in resources) { - var stats = seriesStatistics.SingleOrDefault(ss => ss.SeriesId == series.Id); - if (stats == null) + if (seriesStatistics.TryGetValue(series.Id, out var stats)) { - continue; + LinkSeriesStatistics(series, stats); } - - LinkSeriesStatistics(series, stats); } }