diff options
| author | Luke F <283772+lukefor@users.noreply.github.com> | 2022-09-23 23:09:34 -0400 |
|---|---|---|
| committer | Joshua M. Boniface <joshua@boniface.me> | 2022-09-23 23:09:34 -0400 |
| commit | e579b4d42d4fa934488c29f4feb442d68a677721 (patch) | |
| tree | afc5fec13933319456c0b9c057502cf90d06888c | |
| parent | d3b016aae6edc6dbc18d3dbecbaa488eb7058c23 (diff) | |
Backport pull request #8189 from jellyfin/release-10.8.z
Fix GetItems IndexOutOfRangeException when IDs do not exist
Original-merge: 527ed0607d5f31a232293b39daac19018518b1a0
Merged-by: Claus Vium <cvium@users.noreply.github.com>
Backported-by: Joshua M. Boniface <joshua@boniface.me>
| -rw-r--r-- | MediaBrowser.Controller/Entities/Folder.cs | 24 |
1 files changed, 1 insertions, 23 deletions
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 1860da4c7..92d12a86c 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -892,29 +892,7 @@ namespace MediaBrowser.Controller.Entities private static BaseItem[] SortItemsByRequest(InternalItemsQuery query, IReadOnlyList<BaseItem> items) { - var ids = query.ItemIds; - int size = items.Count; - - // ids can potentially contain non-unique guids, but query result cannot, - // so we include only first occurrence of each guid - var positions = new Dictionary<Guid, int>(size); - int index = 0; - for (int i = 0; i < ids.Length; i++) - { - if (positions.TryAdd(ids[i], index)) - { - index++; - } - } - - var newItems = new BaseItem[size]; - for (int i = 0; i < size; i++) - { - var item = items[i]; - newItems[positions[item.Id]] = item; - } - - return newItems; + return items.OrderBy(i => Array.IndexOf(query.ItemIds, i.Id)).ToArray(); } public QueryResult<BaseItem> GetItems(InternalItemsQuery query) |
