mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-29 19:28:27 -07:00
Use Array.Empty and fix a few multiple enumerations
(cherry picked from commit 11d91faaada0e70910c832ce405ddeed52a24172) Closes #3451
This commit is contained in:
parent
a8db5b240d
commit
adcba7b724
11 changed files with 29 additions and 23 deletions
|
@ -43,11 +43,11 @@ namespace Lidarr.Api.V1
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
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 Lidarr.Http.REST.Attributes;
|
using Lidarr.Http.REST.Attributes;
|
||||||
|
@ -67,7 +68,8 @@ namespace Lidarr.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))
|
||||||
|
|
|
@ -17,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("Lidarr.Common");
|
toLoad.Add("Lidarr.Common");
|
||||||
toLoad.Add(OsInfo.IsWindows ? "Lidarr.Windows" : "Lidarr.Mono");
|
toLoad.Add(OsInfo.IsWindows ? "Lidarr.Windows" : "Lidarr.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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,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;
|
||||||
|
@ -61,7 +62,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>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
@ -135,7 +136,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>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||||
|
|
||||||
if (artistFolder.IsNullOrWhiteSpace() && albumFolder.IsNullOrWhiteSpace())
|
if (artistFolder.IsNullOrWhiteSpace() && albumFolder.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
return new List<MetadataFile>();
|
return Array.Empty<MetadataFile>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var files = new List<MetadataFile>();
|
var files = new List<MetadataFile>();
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace NzbDrone.Core.Indexers
|
||||||
{
|
{
|
||||||
if (!SupportsRss)
|
if (!SupportsRss)
|
||||||
{
|
{
|
||||||
return new List<ReleaseInfo>();
|
return Array.Empty<ReleaseInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FetchReleases(g => g.GetRecentRequests(), true);
|
return FetchReleases(g => g.GetRecentRequests(), true);
|
||||||
|
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Indexers
|
||||||
{
|
{
|
||||||
if (!SupportsSearch)
|
if (!SupportsSearch)
|
||||||
{
|
{
|
||||||
return new List<ReleaseInfo>();
|
return Array.Empty<ReleaseInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
|
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
|
||||||
|
@ -62,7 +62,7 @@ namespace NzbDrone.Core.Indexers
|
||||||
{
|
{
|
||||||
if (!SupportsSearch)
|
if (!SupportsSearch)
|
||||||
{
|
{
|
||||||
return new List<ReleaseInfo>();
|
return Array.Empty<ReleaseInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
|
return FetchReleases(g => g.GetSearchRequests(searchCriteria));
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace NzbDrone.Core.Indexers
|
||||||
|
|
||||||
if (!PostProcess(indexerResponse, items, releases))
|
if (!PostProcess(indexerResponse, items, releases))
|
||||||
{
|
{
|
||||||
return new List<ReleaseInfo>();
|
return Array.Empty<ReleaseInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return releases;
|
return releases;
|
||||||
|
|
|
@ -128,11 +128,12 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
|
||||||
_eventAggregator.PublishEvent(new AlbumEditedEvent(album, album));
|
_eventAggregator.PublishEvent(new AlbumEditedEvent(album, album));
|
||||||
}
|
}
|
||||||
|
|
||||||
var qualifiedImports = decisions.Where(c => c.Approved)
|
var qualifiedImports = decisions
|
||||||
.GroupBy(c => c.Item.Artist.Id, (i, s) => s
|
.Where(decision => decision.Approved)
|
||||||
.OrderByDescending(c => c.Item.Quality, new QualityModelComparer(s.First().Item.Artist.QualityProfile))
|
.GroupBy(decision => decision.Item.Artist.Id)
|
||||||
.ThenByDescending(c => c.Item.Size))
|
.SelectMany(group => group
|
||||||
.SelectMany(c => c)
|
.OrderByDescending(decision => decision.Item.Quality, new QualityModelComparer(group.First().Item.Artist.QualityProfile))
|
||||||
|
.ThenByDescending(decision => decision.Item.Size))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
_logger.ProgressInfo($"Importing {qualifiedImports.Count} tracks");
|
_logger.ProgressInfo($"Importing {qualifiedImports.Count} tracks");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue