diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index a6336f1451..59e4ff1a96 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -205,7 +205,7 @@ namespace Emby.Server.Implementations.Data private static readonly string _mediaAttachmentSaveColumnsSelectQuery = $"select {string.Join(',', _mediaAttachmentSaveColumns)} from mediaattachments where ItemId=@ItemId"; - private static readonly string _mediaAttachmentInsertPrefix; + private static readonly string _mediaAttachmentInsertPrefix = BuildMediaAttachmentInsertPrefix(); private static readonly BaseItemKind[] _programTypes = new[] { @@ -296,21 +296,6 @@ namespace Emby.Server.Implementations.Data { BaseItemKind.Year, typeof(Year).FullName } }; - static SqliteItemRepository() - { - var queryPrefixText = new StringBuilder(); - queryPrefixText.Append("insert into mediaattachments ("); - foreach (var column in _mediaAttachmentSaveColumns) - { - queryPrefixText.Append(column) - .Append(','); - } - - queryPrefixText.Length -= 1; - queryPrefixText.Append(") values "); - _mediaAttachmentInsertPrefix = queryPrefixText.ToString(); - } - /// /// Initializes a new instance of the class. /// @@ -5879,6 +5864,21 @@ AND Type = @InternalPersonType)"); return item; } + private static string BuildMediaAttachmentInsertPrefix() + { + var queryPrefixText = new StringBuilder(); + queryPrefixText.Append("insert into mediaattachments ("); + foreach (var column in _mediaAttachmentSaveColumns) + { + queryPrefixText.Append(column) + .Append(','); + } + + queryPrefixText.Length -= 1; + queryPrefixText.Append(") values "); + return queryPrefixText.ToString(); + } + #nullable enable private readonly struct QueryTimeLogger : IDisposable 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; } } }