Merge pull request #2476 from JustAMan/playto-sort
Bring back sorting when needed to fix PlayTo
This commit is contained in:
commit
c07e1e4f84
|
@ -807,11 +807,45 @@ namespace MediaBrowser.Controller.Entities
|
|||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public QueryResult<BaseItem> GetItems(InternalItemsQuery query)
|
||||
{
|
||||
if (query.ItemIds.Length > 0)
|
||||
{
|
||||
return LibraryManager.GetItemsResult(query);
|
||||
var result = LibraryManager.GetItemsResult(query);
|
||||
|
||||
if (query.OrderBy.Count == 0 && query.ItemIds.Length > 1)
|
||||
{
|
||||
result.Items = SortItemsByRequest(query, result.Items);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return GetItemsInternal(query);
|
||||
|
@ -823,7 +857,14 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
if (query.ItemIds.Length > 0)
|
||||
{
|
||||
return LibraryManager.GetItemList(query);
|
||||
var result = LibraryManager.GetItemList(query);
|
||||
|
||||
if (query.OrderBy.Count == 0 && query.ItemIds.Length > 1)
|
||||
{
|
||||
return SortItemsByRequest(query, result);
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
return GetItemsInternal(query).Items;
|
||||
|
|
Loading…
Reference in New Issue
Block a user