From 71fc475bb39e0439af7b9c6e5289490ea20fad29 Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Wed, 27 Mar 2024 16:17:01 +0100 Subject: [PATCH] Replace LINQ with more direct access method Also rework documentation --- .../Sorting/AlbumArtistComparer.cs | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs index 65c8599e75..59185cdb7e 100644 --- a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs +++ b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using Jellyfin.Data.Enums; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; @@ -9,37 +8,35 @@ using MediaBrowser.Model.Querying; namespace Emby.Server.Implementations.Sorting { /// - /// Class AlbumArtistComparer. + /// Allows comparing artists of albums. Only the first artist of each album is considered. /// public class AlbumArtistComparer : IBaseItemComparer { /// - /// Gets the name. + /// Gets the item type this comparer compares. /// - /// The name. public ItemSortBy Type => ItemSortBy.AlbumArtist; /// - /// Compares the specified x. + /// Compares the specified arguments on their primary artist. /// - /// The x. - /// The y. - /// System.Int32. + /// First item to compare. + /// Second item to compare. + /// Zero if equal, else negative or positive number to indicate order. public int Compare(BaseItem? x, BaseItem? y) { - return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase); + return string.Compare(GetFirstAlbumArtist(x), GetFirstAlbumArtist(y), StringComparison.OrdinalIgnoreCase); } - /// - /// Gets the value. - /// - /// The x. - /// System.String. - private static string? GetValue(BaseItem? x) + private static string? GetFirstAlbumArtist(BaseItem? x) { - var audio = x as IHasAlbumArtist; + if (x is IHasAlbumArtist audio + && audio.AlbumArtists.Count != 0) + { + return audio.AlbumArtists[0]; + } - return audio?.AlbumArtists.FirstOrDefault(); + return null; } } }