Use distinct for artists to avoid double refreshing

This commit is contained in:
cvium 2021-03-10 08:20:02 +01:00
parent 94db751f4b
commit c5a870051a
2 changed files with 7 additions and 13 deletions

View File

@ -1,6 +1,8 @@
#pragma warning disable CS1591
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Library;
namespace MediaBrowser.Controller.Entities.Audio
{
@ -23,15 +25,7 @@ namespace MediaBrowser.Controller.Entities.Audio
public static IEnumerable<string> GetAllArtists<T>(this T item)
where T : IHasArtist, IHasAlbumArtist
{
foreach (var i in item.AlbumArtists)
{
yield return i;
}
foreach (var i in item.Artists)
{
yield return i;
}
return item.AlbumArtists.Concat(item.Artists).DistinctNames();
}
}
}

View File

@ -10,6 +10,10 @@ namespace MediaBrowser.Controller.Library
{
public static class NameExtensions
{
public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
=> names.GroupBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First());
private static string RemoveDiacritics(string? name)
{
if (name == null)
@ -19,9 +23,5 @@ namespace MediaBrowser.Controller.Library
return name.RemoveDiacritics();
}
public static IEnumerable<string> DistinctNames(this IEnumerable<string> names)
=> names.GroupBy(RemoveDiacritics, StringComparer.OrdinalIgnoreCase)
.Select(x => x.First());
}
}