Fix GetItems IndexOutOfRangeException when IDs do not exist
Changes Resolve a System.IndexOutOfRangeException when requesting IDs that do not exist via /Users/.../Items. Previously it was possible for the 'index' values in 'positions' to refer beyond 'size'. It seems the code previously assumed that all requested items exist
[ERR] Error processing request. URL "GET" "/Users/.../Items".
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MediaBrowser.Controller.Entities.Folder.SortItemsByRequest(InternalItemsQuery query, IReadOnlyList`1 items)
at MediaBrowser.Controller.Entities.Folder.GetItems(InternalItemsQuery query)
at Jellyfin.Api.Controllers.ItemsController.GetItems
It caused jellyfin-kodi automatic syncs (i.e. the sync that happens automatically while Kodi is running) to fail as per #3531. I could get a consistent repro by making the same request via curl. With this change, Kodi is automatically syncing again, and the curl request returns correct results.
Issues Fixes #3531
Can you retarget this PR to the release-10.8.z branch? That way we can include it in an patch update.
Have retargeted it to release-10.8.z now
Am I crazy or could the entire method not be simplified to return items.OrderBy(i => ids.IndexOf(i.Id)).ToArray();?
@lukefor Have you had a chance to look at my suggestion?
Have made the suggested change. Problematic curl request is working and returning identical results to the previous fix