The Free Software Media System - Server Backend & API
Backport pull request #15816 from jellyfin/release-10.11.z
theguymadmaxec4744709df1
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.csindex c5dc3b054c..b392340f71 100644--- a/Emby.Server.Implementations/Dto/DtoService.cs+++ b/Emby.Server.Implementations/Dto/DtoService.cs@@ -1051,16 +1051,16 @@ namespace Emby.Server.Implementations.Dto// Include artists that are not in the database yet, e.g., just added via metadata editor// var foundArtists = artistItems.Items.Select(i => i.Item1.Name).ToList();- dto.ArtistItems = _libraryManager.GetArtists([.. hasArtist.Artists.Where(e => !string.IsNullOrWhiteSpace(e))])- .Where(e => e.Value.Length > 0)- .Select(i =>- {- return new NameGuidPair- {- Name = i.Key,- Id = i.Value.First().Id- };- }).Where(i => i is not null).ToArray();+ var artistsLookup = _libraryManager.GetArtists([.. hasArtist.Artists.Where(e => !string.IsNullOrWhiteSpace(e))]);++ dto.ArtistItems = hasArtist.Artists+ .Where(name => !string.IsNullOrWhiteSpace(name))+ .Distinct()+ .Select(name => artistsLookup.TryGetValue(name, out var artists) && artists.Length > 0+ ? new NameGuidPair { Name = name, Id = artists[0].Id }+ : null)+ .Where(item => item is not null)+ .ToArray();}if (item is IHasAlbumArtist hasAlbumArtist)@@ -1085,31 +1085,16 @@ namespace Emby.Server.Implementations.Dto// })// .ToList();- dto.AlbumArtists = hasAlbumArtist.AlbumArtists- // .Except(foundArtists, new DistinctNameComparer())- .Select(i =>- {- // This should not be necessary but we're seeing some cases of it- if (string.IsNullOrEmpty(i))- {- return null;- }-- var artist = _libraryManager.GetArtist(i, new DtoOptions(false)- {- EnableImages = false- });- if (artist is not null)- {- return new NameGuidPair- {- Name = artist.Name,- Id = artist.Id- };- }+ var albumArtistsLookup = _libraryManager.GetArtists([.. hasAlbumArtist.AlbumArtists.Where(e => !string.IsNullOrWhiteSpace(e))]);- return null;- }).Where(i => i is not null).ToArray();+ dto.AlbumArtists = hasAlbumArtist.AlbumArtists+ .Where(name => !string.IsNullOrWhiteSpace(name))+ .Distinct()+ .Select(name => albumArtistsLookup.TryGetValue(name, out var albumArtists) && albumArtists.Length > 0+ ? new NameGuidPair { Name = name, Id = albumArtists[0].Id }+ : null)+ .Where(item => item is not null)+ .ToArray();}// Add video infodiff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.csindex 90aa3a22ee..43a3cdf78f 100644--- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs+++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs@@ -2682,6 +2682,21 @@ public sealed class BaseItemRepository.Where(e => artistNames.Contains(e.Name)).ToArray();- return artists.GroupBy(e => e.Name).ToDictionary(e => e.Key!, e => e.Select(f => DeserializeBaseItem(f)).Where(dto => dto is not null).Cast<MusicArtist>().ToArray());+ var lookup = artists+ .GroupBy(e => e.Name!)+ .ToDictionary(+ g => g.Key,+ g => g.Select(f => DeserializeBaseItem(f)).Where(dto => dto is not null).Cast<MusicArtist>().ToArray());++ var result = new Dictionary<string, MusicArtist[]>(artistNames.Count);+ foreach (var name in artistNames)+ {+ if (lookup.TryGetValue(name, out var artistArray))+ {+ result[name] = artistArray;+ }+ }++ return result;}}