Use DistinctBy introduced in .NET 6
This commit is contained in:
parent
411246e90f
commit
6481376b81
|
@ -574,8 +574,7 @@ namespace Emby.Server.Implementations.Dto
|
||||||
.Where(i => user is null ?
|
.Where(i => user is null ?
|
||||||
true :
|
true :
|
||||||
i.IsVisible(user))
|
i.IsVisible(user))
|
||||||
.GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
.DistinctBy(x => x.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++)
|
||||||
|
|
|
@ -282,19 +282,16 @@ namespace Emby.Server.Implementations.EntryPoints
|
||||||
{
|
{
|
||||||
// Remove dupes in case some were saved multiple times
|
// Remove dupes in case some were saved multiple times
|
||||||
var foldersAddedTo = _foldersAddedTo
|
var foldersAddedTo = _foldersAddedTo
|
||||||
.GroupBy(x => x.Id)
|
.DistinctBy(x => x.Id)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var foldersRemovedFrom = _foldersRemovedFrom
|
var foldersRemovedFrom = _foldersRemovedFrom
|
||||||
.GroupBy(x => x.Id)
|
.DistinctBy(x => x.Id)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var itemsUpdated = _itemsUpdated
|
var itemsUpdated = _itemsUpdated
|
||||||
.Where(i => !_itemsAdded.Contains(i))
|
.Where(i => !_itemsAdded.Contains(i))
|
||||||
.GroupBy(x => x.Id)
|
.DistinctBy(x => x.Id)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
SendChangeNotifications(_itemsAdded.ToList(), itemsUpdated, _itemsRemoved.ToList(), foldersAddedTo, foldersRemovedFrom, CancellationToken.None).GetAwaiter().GetResult();
|
SendChangeNotifications(_itemsAdded.ToList(), itemsUpdated, _itemsRemoved.ToList(), foldersAddedTo, foldersRemovedFrom, CancellationToken.None).GetAwaiter().GetResult();
|
||||||
|
|
|
@ -123,8 +123,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
||||||
var user = _userManager.GetUserById(userId);
|
var user = _userManager.GetUserById(userId);
|
||||||
|
|
||||||
var dtoList = changedItems
|
var dtoList = changedItems
|
||||||
.GroupBy(x => x.Id)
|
.DistinctBy(x => x.Id)
|
||||||
.Select(x => x.First())
|
|
||||||
.Select(i =>
|
.Select(i =>
|
||||||
{
|
{
|
||||||
var dto = _userDataManager.GetUserDataDto(i, user);
|
var dto = _userDataManager.GetUserDataDto(i, user);
|
||||||
|
|
|
@ -133,8 +133,7 @@ namespace Emby.Server.Implementations.IO
|
||||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||||
.Select(GetAffectedBaseItem)
|
.Select(GetAffectedBaseItem)
|
||||||
.Where(item => item is not null)
|
.Where(item => item is not null)
|
||||||
.GroupBy(x => x!.Id) // Removed null values in the previous .Where()
|
.DistinctBy(x => x!.Id)!; // Removed null values in the previous .Where()
|
||||||
.Select(x => x.First())!;
|
|
||||||
|
|
||||||
foreach (var item in itemsToRefresh)
|
foreach (var item in itemsToRefresh)
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,8 +81,7 @@ namespace Emby.Server.Implementations.Images
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}).GroupBy(x => x.Id)
|
}).DistinctBy(x => x.Id);
|
||||||
.Select(x => x.First());
|
|
||||||
|
|
||||||
List<BaseItem> returnItems;
|
List<BaseItem> returnItems;
|
||||||
if (isUsingCollectionStrip)
|
if (isUsingCollectionStrip)
|
||||||
|
|
|
@ -58,8 +58,7 @@ namespace Emby.Server.Implementations.Images
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.Where(i => i is not null)
|
.Where(i => i is not null)
|
||||||
.GroupBy(x => x.Id)
|
.DistinctBy(x => x.Id)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2392,8 +2392,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||||
.Select(i => _libraryManager.FindByPath(i, true))
|
.Select(i => _libraryManager.FindByPath(i, true))
|
||||||
.Where(i => i is not null && i.IsVisibleStandalone(user))
|
.Where(i => i is not null && i.IsVisibleStandalone(user))
|
||||||
.SelectMany(i => _libraryManager.GetCollectionFolders(i))
|
.SelectMany(i => _libraryManager.GetCollectionFolders(i))
|
||||||
.GroupBy(x => x.Id)
|
.DistinctBy(x => x.Id)
|
||||||
.Select(x => x.First())
|
|
||||||
.OrderBy(i => i.SortName)
|
.OrderBy(i => i.SortName)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
|
@ -770,8 +770,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
Name = i.Name,
|
Name = i.Name,
|
||||||
DefaultEnabled = IsSaverEnabledByDefault(i.Name, types, isNewLibrary)
|
DefaultEnabled = IsSaverEnabledByDefault(i.Name, types, isNewLibrary)
|
||||||
})
|
})
|
||||||
.GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
result.MetadataReaders = plugins
|
result.MetadataReaders = plugins
|
||||||
|
@ -781,8 +780,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
Name = i.Name,
|
Name = i.Name,
|
||||||
DefaultEnabled = true
|
DefaultEnabled = true
|
||||||
})
|
})
|
||||||
.GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
result.SubtitleFetchers = plugins
|
result.SubtitleFetchers = plugins
|
||||||
|
@ -792,8 +790,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
Name = i.Name,
|
Name = i.Name,
|
||||||
DefaultEnabled = true
|
DefaultEnabled = true
|
||||||
})
|
})
|
||||||
.GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var typeOptions = new List<LibraryTypeOptionsDto>();
|
var typeOptions = new List<LibraryTypeOptionsDto>();
|
||||||
|
@ -814,8 +811,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
Name = i.Name,
|
Name = i.Name,
|
||||||
DefaultEnabled = IsMetadataFetcherEnabledByDefault(i.Name, type, isNewLibrary)
|
DefaultEnabled = IsMetadataFetcherEnabledByDefault(i.Name, type, isNewLibrary)
|
||||||
})
|
})
|
||||||
.GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToArray(),
|
.ToArray(),
|
||||||
|
|
||||||
ImageFetchers = plugins
|
ImageFetchers = plugins
|
||||||
|
@ -826,8 +822,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
Name = i.Name,
|
Name = i.Name,
|
||||||
DefaultEnabled = IsImageFetcherEnabledByDefault(i.Name, type, isNewLibrary)
|
DefaultEnabled = IsImageFetcherEnabledByDefault(i.Name, type, isNewLibrary)
|
||||||
})
|
})
|
||||||
.GroupBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
||||||
.Select(x => x.First())
|
|
||||||
.ToArray(),
|
.ToArray(),
|
||||||
|
|
||||||
SupportedImageTypes = plugins
|
SupportedImageTypes = plugins
|
||||||
|
|
|
@ -200,8 +200,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
IsMovie = true,
|
IsMovie = true,
|
||||||
EnableGroupByMetadataKey = true,
|
EnableGroupByMetadataKey = true,
|
||||||
DtoOptions = dtoOptions
|
DtoOptions = dtoOptions
|
||||||
}).GroupBy(i => i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvider.Imdb) ?? Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))
|
}).DistinctBy(i => i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvider.Imdb) ?? Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))
|
||||||
.Select(x => x.First())
|
|
||||||
.Take(itemLimit)
|
.Take(itemLimit)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
@ -240,8 +239,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
IsMovie = true,
|
IsMovie = true,
|
||||||
EnableGroupByMetadataKey = true,
|
EnableGroupByMetadataKey = true,
|
||||||
DtoOptions = dtoOptions
|
DtoOptions = dtoOptions
|
||||||
}).GroupBy(i => i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvider.Imdb) ?? Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))
|
}).DistinctBy(i => i.GetProviderId(MediaBrowser.Model.Entities.MetadataProvider.Imdb) ?? Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))
|
||||||
.Select(x => x.First())
|
|
||||||
.Take(itemLimit)
|
.Take(itemLimit)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
|
@ -355,8 +355,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return PhysicalLocations
|
return PhysicalLocations
|
||||||
.Where(i => !FileSystem.AreEqual(i, Path))
|
.Where(i => !FileSystem.AreEqual(i, Path))
|
||||||
.SelectMany(i => GetPhysicalParents(i, rootChildren))
|
.SelectMany(i => GetPhysicalParents(i, rootChildren))
|
||||||
.GroupBy(x => x.Id)
|
.DistinctBy(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)
|
||||||
|
|
|
@ -283,7 +283,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.GroupBy(i => i.Id).Select(x => x.First()).Reverse();
|
return allEpisodes.DistinctBy(i => i.Id).Reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
|
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
|
|
|
@ -10,8 +10,7 @@ namespace MediaBrowser.Controller.Library
|
||||||
public static class NameExtensions
|
public static class NameExtensions
|
||||||
{
|
{
|
||||||
public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
|
public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
|
||||||
=> names.GroupBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase)
|
=> names.DistinctBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase);
|
||||||
.Select(x => x.First());
|
|
||||||
|
|
||||||
private static string RemoveDiacritics(string? name)
|
private static string RemoveDiacritics(string? name)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user