Fixed: Tweak all movies endpoint for better performance from Radarr lists

pull/9154/head
Qstick 1 year ago
parent 248ac9619c
commit e715557a0d

@ -31,22 +31,26 @@ namespace NzbDrone.Core.ImportLists.Radarr
public List<RadarrMovie> GetMovies(RadarrSettings settings) public List<RadarrMovie> GetMovies(RadarrSettings settings)
{ {
return Execute<RadarrMovie>("/api/v3/movie", settings); var requestBuilder = BuildRequest("/api/v3/movie", settings);
requestBuilder.AddQueryParam("excludeLocalCovers", true);
return Execute<RadarrMovie>(requestBuilder, settings);
} }
public List<RadarrProfile> GetProfiles(RadarrSettings settings) public List<RadarrProfile> GetProfiles(RadarrSettings settings)
{ {
return Execute<RadarrProfile>("/api/v3/qualityprofile", settings); return Execute<RadarrProfile>(BuildRequest("/api/v3/qualityprofile", settings), settings);
} }
public List<RadarrRootFolder> GetRootFolders(RadarrSettings settings) public List<RadarrRootFolder> GetRootFolders(RadarrSettings settings)
{ {
return Execute<RadarrRootFolder>("api/v3/rootfolder", settings); return Execute<RadarrRootFolder>(BuildRequest("api/v3/rootfolder", settings), settings);
} }
public List<RadarrTag> GetTags(RadarrSettings settings) public List<RadarrTag> GetTags(RadarrSettings settings)
{ {
return Execute<RadarrTag>("/api/v3/tag", settings); return Execute<RadarrTag>(BuildRequest("/api/v3/tag", settings), settings);
} }
public ValidationFailure Test(RadarrSettings settings) public ValidationFailure Test(RadarrSettings settings)
@ -81,19 +85,23 @@ namespace NzbDrone.Core.ImportLists.Radarr
return null; return null;
} }
private List<TResource> Execute<TResource>(string resource, RadarrSettings settings) private HttpRequestBuilder BuildRequest(string resource, RadarrSettings settings)
{
var baseUrl = settings.BaseUrl.TrimEnd('/');
return new HttpRequestBuilder(baseUrl).Resource(resource)
.Accept(HttpAccept.Json)
.SetHeader("X-Api-Key", settings.ApiKey);
}
private List<TResource> Execute<TResource>(HttpRequestBuilder requestBuilder, RadarrSettings settings)
{ {
if (settings.BaseUrl.IsNullOrWhiteSpace() || settings.ApiKey.IsNullOrWhiteSpace()) if (settings.BaseUrl.IsNullOrWhiteSpace() || settings.ApiKey.IsNullOrWhiteSpace())
{ {
return new List<TResource>(); return new List<TResource>();
} }
var baseUrl = settings.BaseUrl.TrimEnd('/'); var request = requestBuilder.Build();
var request = new HttpRequestBuilder(baseUrl).Resource(resource)
.Accept(HttpAccept.Json)
.SetHeader("X-Api-Key", settings.ApiKey)
.Build();
var response = _httpClient.Get(request); var response = _httpClient.Get(request);

@ -108,7 +108,7 @@ namespace Radarr.Api.V3.Movies
} }
[HttpGet] [HttpGet]
public List<MovieResource> AllMovie(int? tmdbId) public List<MovieResource> AllMovie(int? tmdbId, bool excludeLocalCovers = false)
{ {
var moviesResources = new List<MovieResource>(); var moviesResources = new List<MovieResource>();
@ -135,7 +135,10 @@ namespace Radarr.Api.V3.Movies
var tdict = translations.ToDictionary(x => x.MovieMetadataId); var tdict = translations.ToDictionary(x => x.MovieMetadataId);
if (!excludeLocalCovers)
{
coverFileInfos = _coverMapper.GetCoverFileInfos(); coverFileInfos = _coverMapper.GetCoverFileInfos();
}
var movies = movieTask.GetAwaiter().GetResult(); var movies = movieTask.GetAwaiter().GetResult();
@ -147,7 +150,10 @@ namespace Radarr.Api.V3.Movies
moviesResources.Add(movie.ToResource(availDelay, translation, _qualityUpgradableSpecification)); moviesResources.Add(movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
if (!excludeLocalCovers)
{
MapCoversToLocal(moviesResources, coverFileInfos); MapCoversToLocal(moviesResources, coverFileInfos);
}
var rootFolders = _rootFolderService.All(); var rootFolders = _rootFolderService.All();
@ -271,10 +277,7 @@ namespace Radarr.Api.V3.Movies
[NonAction] [NonAction]
public void Handle(MovieFileImportedEvent message) public void Handle(MovieFileImportedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; BroadcastResourceChange(ModelAction.Updated, MapToResource(message.ImportedMovie.Movie));
var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.ImportedMovie.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.ImportedMovie.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.ImportedMovie.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
[NonAction] [NonAction]
@ -291,19 +294,13 @@ namespace Radarr.Api.V3.Movies
[NonAction] [NonAction]
public void Handle(MovieUpdatedEvent message) public void Handle(MovieUpdatedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; BroadcastResourceChange(ModelAction.Updated, MapToResource(message.Movie));
var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
[NonAction] [NonAction]
public void Handle(MovieEditedEvent message) public void Handle(MovieEditedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; BroadcastResourceChange(ModelAction.Updated, MapToResource(message.Movie));
var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
[NonAction] [NonAction]
@ -318,10 +315,7 @@ namespace Radarr.Api.V3.Movies
[NonAction] [NonAction]
public void Handle(MovieRenamedEvent message) public void Handle(MovieRenamedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; BroadcastResourceChange(ModelAction.Updated, MapToResource(message.Movie));
var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
[NonAction] [NonAction]

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.DecisionEngine.Specifications;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
using NzbDrone.Core.MediaCover; using NzbDrone.Core.MediaCover;

Loading…
Cancel
Save