From cff54d76b9e349935cb9ad75b1cf4d6369ad0d1a Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 17 Sep 2023 00:14:28 -0500 Subject: [PATCH] Fix regression in collections endpoint speed --- .../Collections/CollectionController.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Radarr.Api.V3/Collections/CollectionController.cs b/src/Radarr.Api.V3/Collections/CollectionController.cs index c65f065ac..fa865870a 100644 --- a/src/Radarr.Api.V3/Collections/CollectionController.cs +++ b/src/Radarr.Api.V3/Collections/CollectionController.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Microsoft.AspNetCore.Mvc; using NzbDrone.Common.Extensions; @@ -60,6 +62,7 @@ namespace Radarr.Api.V3.Collections public List GetCollections(int? tmdbId) { var collectionResources = new List(); + var coverFileInfos = _coverMapper.GetCoverFileInfos(); if (tmdbId.HasValue) { @@ -72,7 +75,7 @@ namespace Radarr.Api.V3.Collections } else { - collectionResources = MapToResource(_collectionService.GetAllCollections()).ToList(); + collectionResources = MapToResource(_collectionService.GetAllCollections(), coverFileInfos).ToList(); } return collectionResources; @@ -134,7 +137,7 @@ namespace Radarr.Api.V3.Collections return Accepted(updated); } - private IEnumerable MapToResource(List collections) + private IEnumerable MapToResource(List collections, Dictionary coverFileInfos) { // Avoid calling for naming spec on every movie in filenamebuilder var namingConfig = _namingService.GetConfig(); @@ -150,8 +153,6 @@ namespace Radarr.Api.V3.Collections var movieResource = movie.ToResource(); movieResource.Folder = _fileNameBuilder.GetMovieFolder(new Movie { MovieMetadata = movie }, namingConfig); - _coverMapper.ConvertToLocalUrls(0, movieResource.Images); - if (!existingMoviesTmdbIds.Contains(movie.TmdbId)) { resource.MissingMovies++; @@ -160,6 +161,8 @@ namespace Radarr.Api.V3.Collections resource.Movies.Add(movieResource); } + MapCoversToLocal(resource.Movies, coverFileInfos); + yield return resource; } } @@ -188,6 +191,11 @@ namespace Radarr.Api.V3.Collections return resource; } + private void MapCoversToLocal(IEnumerable movies, Dictionary coverFileInfos) + { + _coverMapper.ConvertToLocalUrls(movies.Select(x => Tuple.Create(0, x.Images.AsEnumerable())), coverFileInfos); + } + [NonAction] public void Handle(CollectionAddedEvent message) {