Remove MoreLINQ

This commit is contained in:
Bond_009 2019-02-02 12:27:06 +01:00
parent 8b073e2ba5
commit 1385d89df6
15 changed files with 53 additions and 116 deletions

View File

@ -70,7 +70,8 @@ namespace Emby.Server.Implementations.Collections
return null; return null;
}) })
.Where(i => i != null) .Where(i => i != null)
.DistinctBy(i => i.Id) .GroupBy(x => x.Id)
.Select(x => x.First())
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.ToList(); .ToList();
} }

View File

@ -620,7 +620,8 @@ namespace Emby.Server.Implementations.Dto
} }
}).Where(i => i != null) }).Where(i => i != null)
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First())
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
for (var i = 0; i < people.Count; i++) for (var i = 0; i < people.Count; i++)

View File

@ -277,14 +277,21 @@ namespace Emby.Server.Implementations.EntryPoints
lock (_libraryChangedSyncLock) lock (_libraryChangedSyncLock)
{ {
// Remove dupes in case some were saved multiple times // Remove dupes in case some were saved multiple times
var foldersAddedTo = _foldersAddedTo.DistinctBy(i => i.Id).ToList(); var foldersAddedTo = _foldersAddedTo
.GroupBy(x => x.Id)
.Select(x => x.First())
.ToList();
var foldersRemovedFrom = _foldersRemovedFrom.DistinctBy(i => i.Id).ToList(); var foldersRemovedFrom = _foldersRemovedFrom
.GroupBy(x => x.Id)
.Select(x => x.First())
.ToList();
var itemsUpdated = _itemsUpdated var itemsUpdated = _itemsUpdated
.Where(i => !_itemsAdded.Contains(i)) .Where(i => !_itemsAdded.Contains(i))
.DistinctBy(i => i.Id) .GroupBy(x => x.Id)
.ToList(); .Select(x => x.First())
.ToList();
SendChangeNotifications(_itemsAdded.ToList(), itemsUpdated, _itemsRemoved.ToList(), foldersAddedTo, foldersRemovedFrom, CancellationToken.None); SendChangeNotifications(_itemsAdded.ToList(), itemsUpdated, _itemsRemoved.ToList(), foldersAddedTo, foldersRemovedFrom, CancellationToken.None);

View File

@ -121,7 +121,8 @@ namespace Emby.Server.Implementations.EntryPoints
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var dtoList = changedItems var dtoList = changedItems
.DistinctBy(i => i.Id) .GroupBy(x => x.Id)
.Select(x => x.First())
.Select(i => .Select(i =>
{ {
var dto = _userDataManager.GetUserDataDto(i, user); var dto = _userDataManager.GetUserDataDto(i, user);

View File

@ -146,8 +146,8 @@ namespace Emby.Server.Implementations.IO
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.Select(GetAffectedBaseItem) .Select(GetAffectedBaseItem)
.Where(item => item != null) .Where(item => item != null)
.DistinctBy(i => i.Id) .GroupBy(x => x.Id)
.ToList(); .Select(x => x.First());
foreach (var item in itemsToRefresh) foreach (var item in itemsToRefresh)
{ {

View File

@ -2464,7 +2464,8 @@ namespace Emby.Server.Implementations.LiveTv
.Where(i => i != null) .Where(i => i != null)
.Where(i => i.IsVisibleStandalone(user)) .Where(i => i.IsVisibleStandalone(user))
.SelectMany(i => _libraryManager.GetCollectionFolders(i)) .SelectMany(i => _libraryManager.GetCollectionFolders(i))
.DistinctBy(i => i.Id) .GroupBy(x => x.Id)
.Select(x => x.First())
.OrderBy(i => i.SortName) .OrderBy(i => i.SortName)
.ToList(); .ToList();

View File

@ -111,7 +111,8 @@ namespace Emby.Server.Implementations.Networking
.OrderBy(i => i.AddressFamily == AddressFamily.InterNetwork ? 0 : 1) .OrderBy(i => i.AddressFamily == AddressFamily.InterNetwork ? 0 : 1)
.ThenBy(i => listClone.IndexOf(i)) .ThenBy(i => listClone.IndexOf(i))
.Where(FilterIpAddress) .Where(FilterIpAddress)
.DistinctBy(i => i.ToString()) .GroupBy(i => i.ToString())
.Select(x => x.First())
.ToList(); .ToList();
} }
@ -429,7 +430,8 @@ namespace Emby.Server.Implementations.Networking
return new List<IPAddress>(); return new List<IPAddress>();
} }
}).DistinctBy(i => i.ToString()) }).GroupBy(i => i.ToString())
.Select(x => x.First())
.ToList(); .ToList();
} }

View File

@ -13,7 +13,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists; using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
@ -64,7 +63,8 @@ namespace Emby.Server.Implementations.Playlists
}) })
.Where(i => i != null) .Where(i => i != null)
.OrderBy(i => Guid.NewGuid()) .OrderBy(i => Guid.NewGuid())
.DistinctBy(i => i.Id) .GroupBy(x => x.Id)
.Select(x => x.First())
.ToList(); .ToList();
} }
} }

View File

@ -12,7 +12,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
namespace Emby.Server.Implementations.UserViews namespace Emby.Server.Implementations.UserViews
@ -83,7 +82,8 @@ namespace Emby.Server.Implementations.UserViews
return i; return i;
}).DistinctBy(i => i.Id); }).GroupBy(x => x.Id)
.Select(x => x.First());
if (isUsingCollectionStrip) if (isUsingCollectionStrip)
{ {

View File

@ -551,7 +551,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name, Name = i.Name,
DefaultEnabled = IsSaverEnabledByDefault(i.Name, types, isNewLibrary) DefaultEnabled = IsSaverEnabledByDefault(i.Name, types, isNewLibrary)
}) })
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First())
.ToArray(); .ToArray();
result.MetadataReaders = plugins result.MetadataReaders = plugins
@ -561,7 +562,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name, Name = i.Name,
DefaultEnabled = true DefaultEnabled = true
}) })
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First())
.ToArray(); .ToArray();
result.SubtitleFetchers = plugins result.SubtitleFetchers = plugins
@ -571,7 +573,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name, Name = i.Name,
DefaultEnabled = true DefaultEnabled = true
}) })
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First())
.ToArray(); .ToArray();
var typeOptions = new List<LibraryTypeOptions>(); var typeOptions = new List<LibraryTypeOptions>();
@ -593,7 +596,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name, Name = i.Name,
DefaultEnabled = IsMetadataFetcherEnabledByDefault(i.Name, type, isNewLibrary) DefaultEnabled = IsMetadataFetcherEnabledByDefault(i.Name, type, isNewLibrary)
}) })
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First())
.ToArray(), .ToArray(),
ImageFetchers = plugins ImageFetchers = plugins
@ -604,7 +608,8 @@ namespace MediaBrowser.Api.Library
Name = i.Name, Name = i.Name,
DefaultEnabled = IsImageFetcherEnabledByDefault(i.Name, type, isNewLibrary) DefaultEnabled = IsImageFetcherEnabledByDefault(i.Name, type, isNewLibrary)
}) })
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase) .GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First())
.ToArray(), .ToArray(),
SupportedImageTypes = plugins SupportedImageTypes = plugins

View File

@ -268,7 +268,8 @@ namespace MediaBrowser.Api.Movies
EnableGroupByMetadataKey = true, EnableGroupByMetadataKey = true,
DtoOptions = dtoOptions DtoOptions = dtoOptions
}).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N")) }).GroupBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
.Select(x => x.First())
.Take(itemLimit) .Take(itemLimit)
.ToList(); .ToList();
@ -308,7 +309,8 @@ namespace MediaBrowser.Api.Movies
EnableGroupByMetadataKey = true, EnableGroupByMetadataKey = true,
DtoOptions = dtoOptions DtoOptions = dtoOptions
}).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N")) }).GroupBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N"))
.Select(x => x.First())
.Take(itemLimit) .Take(itemLimit)
.ToList(); .ToList();

View File

@ -335,7 +335,11 @@ namespace MediaBrowser.Controller.Entities
.OfType<Folder>() .OfType<Folder>()
.ToList(); .ToList();
return PhysicalLocations.Where(i => !FileSystem.AreEqual(i, Path)).SelectMany(i => GetPhysicalParents(i, rootChildren)).DistinctBy(i => i.Id); return PhysicalLocations
.Where(i => !FileSystem.AreEqual(i, Path))
.SelectMany(i => GetPhysicalParents(i, rootChildren))
.GroupBy(x => x.Id)
.Select(x => x.First());
} }
private IEnumerable<Folder> GetPhysicalParents(string path, List<Folder> rootChildren) private IEnumerable<Folder> GetPhysicalParents(string path, List<Folder> rootChildren)

View File

@ -270,7 +270,7 @@ namespace MediaBrowser.Controller.Entities.TV
// This depends on settings for that series // This depends on settings for that series
// When this happens, remove the duplicate from season 0 // When this happens, remove the duplicate from season 0
return allEpisodes.DistinctBy(i => i.Id).Reverse(); return allEpisodes.GroupBy(i => i.Id).Select(x => x.First()).Reverse();
} }
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken) public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using MediaBrowser.Controller.Extensions; using MediaBrowser.Controller.Extensions;
using MediaBrowser.Model.Extensions;
namespace MediaBrowser.Controller.Library namespace MediaBrowser.Controller.Library
{ {
@ -14,13 +14,11 @@ namespace MediaBrowser.Controller.Library
return string.Empty; return string.Empty;
} }
//return name;
return name.RemoveDiacritics(); return name.RemoveDiacritics();
} }
public static IEnumerable<string> DistinctNames(this IEnumerable<string> names) public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
{ => names.GroupBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase)
return names.DistinctBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase); .Select(x => x.First());
}
} }
} }

View File

@ -1,85 +0,0 @@
using System;
using System.Collections.Generic;
// TODO: @bond Remove
namespace MediaBrowser.Model.Extensions
{
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2008 Jonathan Skeet. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
public static class LinqExtensions
{
/// <summary>
/// Returns all distinct elements of the given source, where "distinctness"
/// is determined via a projection and the default equality comparer for the projected type.
/// </summary>
/// <remarks>
/// This operator uses deferred execution and streams the results, although
/// a set of already-seen keys is retained. If a key is seen multiple times,
/// only the first element with that key is returned.
/// </remarks>
/// <typeparam name="TSource">Type of the source sequence</typeparam>
/// <typeparam name="TKey">Type of the projected element</typeparam>
/// <param name="source">Source sequence</param>
/// <param name="keySelector">Projection for determining "distinctness"</param>
/// <returns>A sequence consisting of distinct elements from the source sequence,
/// comparing them by the specified key projection.</returns>
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)
{
return source.DistinctBy(keySelector, null);
}
/// <summary>
/// Returns all distinct elements of the given source, where "distinctness"
/// is determined via a projection and the specified comparer for the projected type.
/// </summary>
/// <remarks>
/// This operator uses deferred execution and streams the results, although
/// a set of already-seen keys is retained. If a key is seen multiple times,
/// only the first element with that key is returned.
/// </remarks>
/// <typeparam name="TSource">Type of the source sequence</typeparam>
/// <typeparam name="TKey">Type of the projected element</typeparam>
/// <param name="source">Source sequence</param>
/// <param name="keySelector">Projection for determining "distinctness"</param>
/// <param name="comparer">The equality comparer to use to determine whether or not keys are equal.
/// If null, the default equality comparer for <c>TSource</c> is used.</param>
/// <returns>A sequence consisting of distinct elements from the source sequence,
/// comparing them by the specified key projection.</returns>
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
return DistinctByImpl(source, keySelector, comparer);
}
private static IEnumerable<TSource> DistinctByImpl<TSource, TKey>(IEnumerable<TSource> source,
Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
var knownKeys = new HashSet<TKey>(comparer);
foreach (var element in source)
{
if (knownKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
}