mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Use Array.Empty and fix a few multiple enumerations
(cherry picked from commit 11d91faaada0e70910c832ce405ddeed52a24172)
This commit is contained in:
parent
c987824174
commit
044de922fa
@ -16,7 +16,7 @@ static AssemblyLoader()
|
||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ContainerResolveEventHandler);
|
||||
}
|
||||
|
||||
public static IEnumerable<Assembly> Load(IEnumerable<string> assemblyNames)
|
||||
public static IList<Assembly> Load(IList<string> assemblyNames)
|
||||
{
|
||||
var toLoad = assemblyNames.ToList();
|
||||
toLoad.Add("Radarr.Common");
|
||||
@ -28,8 +28,9 @@ public static IEnumerable<Assembly> Load(IEnumerable<string> assemblyNames)
|
||||
|
||||
var startupPath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
return toLoad.Select(x =>
|
||||
AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(startupPath, $"{x}.dll")));
|
||||
return toLoad
|
||||
.Select(x => AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(startupPath, $"{x}.dll")))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static Assembly ContainerResolveEventHandler(object sender, ResolveEventArgs args)
|
||||
|
@ -14,14 +14,14 @@ public virtual WebParameter this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
var parameters = this.Where(p => p.Name.Equals(name));
|
||||
var parameters = this.Where(p => p.Name.Equals(name)).ToArray();
|
||||
|
||||
if (!parameters.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (parameters.Count() == 1)
|
||||
if (parameters.Length == 1)
|
||||
{
|
||||
return parameters.Single();
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public IEnumerable<TModel> Get(IEnumerable<int> ids)
|
||||
{
|
||||
if (!ids.Any())
|
||||
{
|
||||
return new List<TModel>();
|
||||
return Array.Empty<TModel>();
|
||||
}
|
||||
|
||||
var result = Query(x => ids.Contains(x.Id));
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using NLog;
|
||||
@ -61,7 +62,7 @@ public IEnumerable<DownloadStationTask> GetTasks(DownloadStationSettings setting
|
||||
catch (DownloadClientException e)
|
||||
{
|
||||
_logger.Error(e);
|
||||
return new List<DownloadStationTask>();
|
||||
return Array.Empty<DownloadStationTask>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@ -135,7 +136,7 @@ public IEnumerable<DownloadStationTask> GetTasks(DownloadStationSettings setting
|
||||
catch (DownloadClientException e)
|
||||
{
|
||||
_logger.Error(e);
|
||||
return new List<DownloadStationTask>();
|
||||
return Array.Empty<DownloadStationTask>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ public override IEnumerable<ExtraFile> CreateAfterMovieFolder(Movie movie, strin
|
||||
|
||||
if (movieFolder.IsNullOrWhiteSpace())
|
||||
{
|
||||
return new List<MetadataFile>();
|
||||
return Array.Empty<MetadataFile>();
|
||||
}
|
||||
|
||||
var files = new List<MetadataFile>();
|
||||
|
@ -42,7 +42,7 @@ public override IList<ReleaseInfo> FetchRecent()
|
||||
{
|
||||
if (!SupportsRss)
|
||||
{
|
||||
return new List<ReleaseInfo>();
|
||||
return Array.Empty<ReleaseInfo>();
|
||||
}
|
||||
|
||||
return FetchReleases(g => g.GetRecentRequests(), true);
|
||||
@ -52,7 +52,7 @@ public override IList<ReleaseInfo> Fetch(MovieSearchCriteria searchCriteria)
|
||||
{
|
||||
if (!SupportsSearch)
|
||||
{
|
||||
return new List<ReleaseInfo>();
|
||||
return Array.Empty<ReleaseInfo>();
|
||||
}
|
||||
|
||||
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
|
||||
|
@ -85,7 +85,7 @@ public virtual IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
||||
|
||||
if (!PostProcess(indexerResponse, items, releases))
|
||||
{
|
||||
return new List<ReleaseInfo>();
|
||||
return Array.Empty<ReleaseInfo>();
|
||||
}
|
||||
|
||||
return releases;
|
||||
|
@ -57,11 +57,12 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
||||
_logger.Debug("Decisions: {0}", decisions.Count);
|
||||
|
||||
// I added a null op for the rare case that the quality is null. TODO: find out why that would even happen in the first place.
|
||||
var qualifiedImports = decisions.Where(c => c.Approved)
|
||||
.GroupBy(c => c.LocalMovie.Movie.Id, (i, s) => s
|
||||
.OrderByDescending(c => c.LocalMovie.Quality ?? new QualityModel { Quality = Quality.Unknown }, new QualityModelComparer(s.First().LocalMovie.Movie.Profile))
|
||||
.ThenByDescending(c => c.LocalMovie.Size))
|
||||
.SelectMany(c => c)
|
||||
var qualifiedImports = decisions
|
||||
.Where(decision => decision.Approved)
|
||||
.GroupBy(decision => decision.LocalMovie.Movie.Id)
|
||||
.SelectMany(group => group
|
||||
.OrderByDescending(decision => decision.LocalMovie.Quality ?? new QualityModel { Quality = Quality.Unknown }, new QualityModelComparer(group.First().LocalMovie.Movie.Profile))
|
||||
.ThenByDescending(decision => decision.LocalMovie.Size))
|
||||
.ToList();
|
||||
|
||||
var importResults = new List<ImportResult>();
|
||||
|
@ -43,11 +43,11 @@ protected override TProviderResource GetResourceById(int id)
|
||||
[HttpGet]
|
||||
public List<TProviderResource> GetAll()
|
||||
{
|
||||
var providerDefinitions = _providerFactory.All().OrderBy(p => p.ImplementationName);
|
||||
var providerDefinitions = _providerFactory.All();
|
||||
|
||||
var result = new List<TProviderResource>(providerDefinitions.Count());
|
||||
var result = new List<TProviderResource>(providerDefinitions.Count);
|
||||
|
||||
foreach (var definition in providerDefinitions)
|
||||
foreach (var definition in providerDefinitions.OrderBy(p => p.ImplementationName))
|
||||
{
|
||||
_providerFactory.SetProviderCharacteristics(definition);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -79,7 +80,8 @@ public override void OnActionExecuting(ActionExecutingContext context)
|
||||
}
|
||||
}
|
||||
|
||||
var attributes = descriptor.MethodInfo.CustomAttributes;
|
||||
var attributes = descriptor.MethodInfo.CustomAttributes as IReadOnlyCollection<CustomAttributeData> ??
|
||||
descriptor.MethodInfo.CustomAttributes.ToArray();
|
||||
if (attributes.Any(x => VALIDATE_ID_ATTRIBUTES.Contains(x.AttributeType)) && !skipValidate)
|
||||
{
|
||||
if (context.ActionArguments.TryGetValue("id", out var idObj))
|
||||
|
Loading…
Reference in New Issue
Block a user