The Free Software Media System - Server Backend & API
Use ToList() instead of ToArray() on sequences of unknown size
Mark Monteiro3cb98fba5530
diff --git a/Emby.Server.Implementations/Playlists/PlaylistManager.cs b/Emby.Server.Implementations/Playlists/PlaylistManager.csindex 42d14a9e5b..5a6ecf5c17 100644--- a/Emby.Server.Implementations/Playlists/PlaylistManager.cs+++ b/Emby.Server.Implementations/Playlists/PlaylistManager.cs@@ -196,7 +196,7 @@ namespace Emby.Server.Implementations.Playlists// Retrieve all the items to be added to the playlistvar items = GetPlaylistItems(itemIds, playlist.MediaType, user, options).Where(i => i.SupportsAddingToPlaylist)- .ToArray();+ .ToList();// Remove duplicates from the new items to be addedvar existingIds = playlist.LinkedChildren.Select(c => c.ItemId).ToHashSet();@@ -205,23 +205,23 @@ namespace Emby.Server.Implementations.Playlists.GroupBy(i => i.Id).Select(group => group.First()).Select(i => LinkedChild.Create(i))- .ToArray();+ .ToList();// Log duplicates that have been ignored, if any- int numDuplicates = items.Length - uniqueItems.Length;+ int numDuplicates = items.Count - uniqueItems.Count;if (numDuplicates > 0){_logger.LogWarning("Ignored adding {DuplicateCount} duplicate items to playlist {PlaylistName}.", numDuplicates, playlist.Name);}// Do nothing else if there are no items to add to the playlist- if (uniqueItems.Length == 0)+ if (uniqueItems.Count == 0){return;}// Create a new array with the updated playlist items- var newLinkedChildren = new LinkedChild[playlist.LinkedChildren.Length + uniqueItems.Length];+ var newLinkedChildren = new LinkedChild[playlist.LinkedChildren.Length + uniqueItems.Count];playlist.LinkedChildren.CopyTo(newLinkedChildren, 0);uniqueItems.CopyTo(newLinkedChildren, playlist.LinkedChildren.Length);