Remove unnecessary ToList usage

This commit is contained in:
ignacio laborde 2022-01-04 13:05:36 -03:00 committed by jgriff6
parent 790f67aac1
commit c6bf6e00de
8 changed files with 17 additions and 32 deletions

View File

@ -127,8 +127,7 @@ namespace Emby.Dlna.Eventing
public Task TriggerEvent(string notificationType, IDictionary<string, string> stateVariables) public Task TriggerEvent(string notificationType, IDictionary<string, string> stateVariables)
{ {
var subs = _subscriptions.Values var subs = _subscriptions.Values
.Where(i => !i.IsExpired && string.Equals(notificationType, i.NotificationType, StringComparison.OrdinalIgnoreCase)) .Where(i => !i.IsExpired && string.Equals(notificationType, i.NotificationType, StringComparison.OrdinalIgnoreCase));
.ToList();
var tasks = subs.Select(i => TriggerEvent(i, stateVariables)); var tasks = subs.Select(i => TriggerEvent(i, stateVariables));

View File

@ -36,8 +36,7 @@ namespace Emby.Naming.AudioBook
// File with empty fullname will be sorted out here. // File with empty fullname will be sorted out here.
var audiobookFileInfos = files var audiobookFileInfos = files
.Select(i => _audioBookResolver.Resolve(i.FullName)) .Select(i => _audioBookResolver.Resolve(i.FullName))
.OfType<AudioBookFileInfo>() .OfType<AudioBookFileInfo>();
.ToList();
var stackResult = StackResolver.ResolveAudioBooks(audiobookFileInfos); var stackResult = StackResolver.ResolveAudioBooks(audiobookFileInfos);
@ -102,8 +101,7 @@ namespace Emby.Naming.AudioBook
{ {
var extra = ex var extra = ex
.OrderBy(x => x.Container) .OrderBy(x => x.Container)
.ThenBy(x => x.Path) .ThenBy(x => x.Path);
.ToList();
stackFiles = stackFiles.Except(extra).ToList(); stackFiles = stackFiles.Except(extra).ToList();
extras.AddRange(extra); extras.AddRange(extra);

View File

@ -29,7 +29,7 @@ namespace Emby.Naming.Video
.Where(i => i.ExtraType == null) .Where(i => i.ExtraType == null)
.Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = i.IsDirectory }); .Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = i.IsDirectory });
var stackResult = StackResolver.Resolve(nonExtras, namingOptions).ToList(); var stackResult = StackResolver.Resolve(nonExtras, namingOptions);
var remainingFiles = new List<VideoFileInfo>(); var remainingFiles = new List<VideoFileInfo>();
var standaloneMedia = new List<VideoFileInfo>(); var standaloneMedia = new List<VideoFileInfo>();

View File

@ -88,8 +88,7 @@ namespace Emby.Notifications
string description, string description,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
users = users.Where(i => IsEnabledForUser(service, i)) users = users.Where(i => IsEnabledForUser(service, i));
.ToList();
var tasks = users.Select(i => SendNotification(request, service, title, description, i, cancellationToken)); var tasks = users.Select(i => SendNotification(request, service, title, description, i, cancellationToken));

View File

@ -210,7 +210,7 @@ namespace Emby.Server.Implementations.Collections
var itemList = new List<BaseItem>(); var itemList = new List<BaseItem>();
var linkedChildrenList = collection.GetLinkedChildren(); var linkedChildrenList = collection.GetLinkedChildren();
var currentLinkedChildrenIds = linkedChildrenList.Select(i => i.Id).ToList(); var currentLinkedChildrenIds = linkedChildrenList.Select(i => i.Id);
foreach (var id in ids) foreach (var id in ids)
{ {
@ -232,10 +232,7 @@ namespace Emby.Server.Implementations.Collections
if (list.Count > 0) if (list.Count > 0)
{ {
var newList = collection.LinkedChildren.ToList(); collection.LinkedChildren = collection.LinkedChildren.Concat(list).ToArray();
newList.AddRange(list);
collection.LinkedChildren = newList.ToArray();
collection.UpdateRatingToItems(linkedChildrenList); collection.UpdateRatingToItems(linkedChildrenList);
await collection.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); await collection.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
@ -303,7 +300,7 @@ namespace Emby.Server.Implementations.Collections
{ {
var results = new Dictionary<Guid, BaseItem>(); var results = new Dictionary<Guid, BaseItem>();
var allBoxSets = GetCollections(user).ToList(); var allBoxSets = GetCollections(user);
foreach (var item in items) foreach (var item in items)
{ {

View File

@ -115,7 +115,7 @@ namespace Emby.Server.Implementations.EntryPoints
{ {
} }
var collectionFolders = _libraryManager.GetCollectionFolders(item).ToList(); var collectionFolders = _libraryManager.GetCollectionFolders(item);
foreach (var collectionFolder in collectionFolders) foreach (var collectionFolder in collectionFolders)
{ {

View File

@ -82,9 +82,7 @@ namespace Emby.Server.Implementations.IO
public bool IsPathLocked(string path) public bool IsPathLocked(string path)
{ {
// This method is not used by the core but it used by auto-organize // This method is not used by the core but it used by auto-organize
return _tempIgnoredPaths.Keys.Any(i => _fileSystem.AreEqual(i, path) || _fileSystem.ContainsSubPath(i, path));
var lockedPaths = _tempIgnoredPaths.Keys.ToList();
return lockedPaths.Any(i => _fileSystem.AreEqual(i, path) || _fileSystem.ContainsSubPath(i, path));
} }
public async void ReportFileSystemChangeComplete(string path, bool refreshPath) public async void ReportFileSystemChangeComplete(string path, bool refreshPath)
@ -145,8 +143,7 @@ namespace Emby.Server.Implementations.IO
.OfType<Folder>() .OfType<Folder>()
.SelectMany(f => f.PhysicalLocations) .SelectMany(f => f.PhysicalLocations)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(i => i) .OrderBy(i => i);
.ToList();
foreach (var path in paths) foreach (var path in paths)
{ {
@ -372,11 +369,8 @@ namespace Emby.Server.Implementations.IO
var monitorPath = !IgnorePatterns.ShouldIgnore(path); var monitorPath = !IgnorePatterns.ShouldIgnore(path);
// Ignore certain files // Ignore certain files, If the parent of an ignored path has a change event, ignore that too
var tempIgnorePaths = _tempIgnoredPaths.Keys.ToList(); if (_tempIgnoredPaths.Keys.Any(i =>
// If the parent of an ignored path has a change event, ignore that too
if (tempIgnorePaths.Any(i =>
{ {
if (_fileSystem.AreEqual(i, path)) if (_fileSystem.AreEqual(i, path))
{ {
@ -491,7 +485,7 @@ namespace Emby.Server.Implementations.IO
{ {
lock (_activeRefreshers) lock (_activeRefreshers)
{ {
foreach (var refresher in _activeRefreshers.ToList()) foreach (var refresher in _activeRefreshers)
{ {
refresher.Completed -= OnNewRefresherCompleted; refresher.Completed -= OnNewRefresherCompleted;
refresher.Dispose(); refresher.Dispose();

View File

@ -356,7 +356,7 @@ namespace Emby.Server.Implementations.Library
} }
var children = item.IsFolder var children = item.IsFolder
? ((Folder)item).GetRecursiveChildren(false).ToList() ? ((Folder)item).GetRecursiveChildren(false)
: new List<BaseItem>(); : new List<BaseItem>();
foreach (var metadataPath in GetMetadataPaths(item, children)) foreach (var metadataPath in GetMetadataPaths(item, children))
@ -612,11 +612,9 @@ namespace Emby.Server.Implementations.Library
var list = originalList.Where(i => i.IsDirectory) var list = originalList.Where(i => i.IsDirectory)
.Select(i => _fileSystem.NormalizePath(i.FullName)) .Select(i => _fileSystem.NormalizePath(i.FullName))
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase);
.ToList();
var dupes = list.Where(subPath => !subPath.EndsWith(":\\", StringComparison.OrdinalIgnoreCase) && list.Any(i => _fileSystem.ContainsSubPath(i, subPath))) var dupes = list.Where(subPath => !subPath.EndsWith(":\\", StringComparison.OrdinalIgnoreCase) && list.Any(i => _fileSystem.ContainsSubPath(i, subPath)));
.ToList();
foreach (var dupe in dupes) foreach (var dupe in dupes)
{ {