mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Fixed: Use Array.Empty and fix a few multiple enumerations
(cherry picked from commit 11d91faaada0e70910c832ce405ddeed52a24172)
This commit is contained in:
@@ -5,8 +5,6 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
namespace NzbDrone.Common.Composition
|
namespace NzbDrone.Common.Composition
|
||||||
@@ -19,16 +17,17 @@ namespace NzbDrone.Common.Composition
|
|||||||
RegisterSQLiteResolver();
|
RegisterSQLiteResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<Assembly> Load(IEnumerable<string> assemblies)
|
public static IList<Assembly> Load(IList<string> assemblyNames)
|
||||||
{
|
{
|
||||||
var toLoad = assemblies.ToList();
|
var toLoad = assemblyNames.ToList();
|
||||||
toLoad.Add("Prowlarr.Common");
|
toLoad.Add("Prowlarr.Common");
|
||||||
toLoad.Add(OsInfo.IsWindows ? "Prowlarr.Windows" : "Prowlarr.Mono");
|
toLoad.Add(OsInfo.IsWindows ? "Prowlarr.Windows" : "Prowlarr.Mono");
|
||||||
|
|
||||||
var startupPath = AppDomain.CurrentDomain.BaseDirectory;
|
var startupPath = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
|
||||||
return toLoad.Select(x =>
|
return toLoad
|
||||||
AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(startupPath, $"{x}.dll")));
|
.Select(x => AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(startupPath, $"{x}.dll")))
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Assembly ContainerResolveEventHandler(object sender, ResolveEventArgs args)
|
private static Assembly ContainerResolveEventHandler(object sender, ResolveEventArgs args)
|
||||||
|
@@ -14,14 +14,14 @@ namespace NzbDrone.Common.OAuth
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var parameters = this.Where(p => p.Name.Equals(name));
|
var parameters = this.Where(p => p.Name.Equals(name)).ToArray();
|
||||||
|
|
||||||
if (!parameters.Any())
|
if (!parameters.Any())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parameters.Count() == 1)
|
if (parameters.Length == 1)
|
||||||
{
|
{
|
||||||
return parameters.Single();
|
return parameters.Single();
|
||||||
}
|
}
|
||||||
|
@@ -103,7 +103,7 @@ namespace NzbDrone.Core.Datastore
|
|||||||
{
|
{
|
||||||
if (!ids.Any())
|
if (!ids.Any())
|
||||||
{
|
{
|
||||||
return new List<TModel>();
|
return Array.Empty<TModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = Query(x => ids.Contains(x.Id));
|
var result = Query(x => ids.Contains(x.Id));
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using NLog;
|
using NLog;
|
||||||
@@ -64,7 +65,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
|
|||||||
catch (DownloadClientException e)
|
catch (DownloadClientException e)
|
||||||
{
|
{
|
||||||
_logger.Error(e);
|
_logger.Error(e);
|
||||||
return new List<DownloadStationTask>();
|
return Array.Empty<DownloadStationTask>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||||||
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]",
|
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]",
|
||||||
RegexOptions.Compiled);
|
RegexOptions.Compiled);
|
||||||
|
|
||||||
public List<ReleaseInfo> Releases { get; set; }
|
public IList<ReleaseInfo> Releases { get; set; }
|
||||||
|
|
||||||
private static string RemoveInvalidXMLChars(string text)
|
private static string RemoveInvalidXMLChars(string text)
|
||||||
{
|
{
|
||||||
|
@@ -148,7 +148,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<ReleaseInfo>> Dispatch(Func<IIndexer, Task<IndexerPageableQueryResult>> searchAction, SearchCriteriaBase criteriaBase)
|
private async Task<IList<ReleaseInfo>> Dispatch(Func<IIndexer, Task<IndexerPageableQueryResult>> searchAction, SearchCriteriaBase criteriaBase)
|
||||||
{
|
{
|
||||||
var indexers = _indexerFactory.Enabled();
|
var indexers = _indexerFactory.Enabled();
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||||||
if (indexers.Count == 0)
|
if (indexers.Count == 0)
|
||||||
{
|
{
|
||||||
_logger.Debug("All provided categories are unsupported by selected indexers: {0}", string.Join(", ", criteriaBase.Categories));
|
_logger.Debug("All provided categories are unsupported by selected indexers: {0}", string.Join(", ", criteriaBase.Categories));
|
||||||
return new List<ReleaseInfo>();
|
return Array.Empty<ReleaseInfo>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||||||
{
|
{
|
||||||
if (_indexerLimitService.AtQueryLimit((IndexerDefinition)indexer.Definition))
|
if (_indexerLimitService.AtQueryLimit((IndexerDefinition)indexer.Definition))
|
||||||
{
|
{
|
||||||
return new List<ReleaseInfo>();
|
return Array.Empty<ReleaseInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -224,7 +224,7 @@ namespace NzbDrone.Core.IndexerSearch
|
|||||||
_logger.Error(e, "Error while searching for {0}", criteriaBase);
|
_logger.Error(e, "Error while searching for {0}", criteriaBase);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<ReleaseInfo>();
|
return Array.Empty<ReleaseInfo>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -93,7 +93,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(input))
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
{
|
{
|
||||||
return new List<IndexerCategory>();
|
return Array.Empty<IndexerCategory>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cats = _categoryMapping
|
var cats = _categoryMapping
|
||||||
@@ -109,7 +109,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(trackerCategoryDesc))
|
if (string.IsNullOrWhiteSpace(trackerCategoryDesc))
|
||||||
{
|
{
|
||||||
return new List<IndexerCategory>();
|
return Array.Empty<IndexerCategory>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cats = _categoryMapping
|
var cats = _categoryMapping
|
||||||
|
@@ -189,7 +189,7 @@ namespace NzbDrone.Core.Indexers
|
|||||||
|
|
||||||
public override IEnumerable<IndexerDefinition> GetPresetDefinitions(IndexerDefinition providerDefinition)
|
public override IEnumerable<IndexerDefinition> GetPresetDefinitions(IndexerDefinition providerDefinition)
|
||||||
{
|
{
|
||||||
return new List<IndexerDefinition>();
|
return Array.Empty<IndexerDefinition>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetProviderCharacteristics(IIndexer provider, IndexerDefinition definition)
|
public override void SetProviderCharacteristics(IIndexer provider, IndexerDefinition definition)
|
||||||
|
@@ -82,7 +82,12 @@ namespace NzbDrone.Core.Indexers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !PostProcess(indexerResponse, items, releases) ? new List<ReleaseInfo>() : releases;
|
if (!PostProcess(indexerResponse, items, releases))
|
||||||
|
{
|
||||||
|
return Array.Empty<ReleaseInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
|
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
|
||||||
|
@@ -44,11 +44,11 @@ namespace Prowlarr.Api.V1
|
|||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public List<TProviderResource> GetAll()
|
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);
|
_providerFactory.SetProviderCharacteristics(definition);
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -73,7 +74,8 @@ namespace Prowlarr.Http.REST
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (attributes.Any(x => VALIDATE_ID_ATTRIBUTES.Contains(x.AttributeType)) && !skipValidate)
|
||||||
{
|
{
|
||||||
if (context.ActionArguments.TryGetValue("id", out var idObj))
|
if (context.ActionArguments.TryGetValue("id", out var idObj))
|
||||||
|
Reference in New Issue
Block a user