Merge pull request #1011 from Bond-009/order

Don't try to order the response the same as the request
pull/1020/head
Vasily 6 years ago committed by GitHub
commit 8c2af50170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,8 +5,6 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common; using MediaBrowser.Common;
using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
@ -21,8 +19,6 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -83,15 +79,8 @@ namespace Emby.Server.Implementations.Dto
return GetBaseItemDto(item, options, user, owner); return GetBaseItemDto(item, options, user, owner);
} }
public BaseItemDto[] GetBaseItemDtos(List<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null) public BaseItemDto[] GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
{ => GetBaseItemDtos(items, items.Count, options, user, owner);
return GetBaseItemDtos(items, items.Count, options, user, owner);
}
public BaseItemDto[] GetBaseItemDtos(BaseItem[] items, DtoOptions options, User user = null, BaseItem owner = null)
{
return GetBaseItemDtos(items, items.Length, options, user, owner);
}
public BaseItemDto[] GetBaseItemDtos(IEnumerable<BaseItem> items, int itemCount, DtoOptions options, User user = null, BaseItem owner = null) public BaseItemDto[] GetBaseItemDtos(IEnumerable<BaseItem> items, int itemCount, DtoOptions options, User user = null, BaseItem owner = null)
{ {

@ -1090,7 +1090,7 @@ namespace Emby.Server.Implementations.Session
await SendMessageToSession(session, "Play", command, cancellationToken).ConfigureAwait(false); await SendMessageToSession(session, "Play", command, cancellationToken).ConfigureAwait(false);
} }
private IList<BaseItem> TranslateItemForPlayback(Guid id, User user) private IEnumerable<BaseItem> TranslateItemForPlayback(Guid id, User user)
{ {
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);

@ -171,19 +171,12 @@ namespace MediaBrowser.Api
} }
if (!string.IsNullOrWhiteSpace(hasDtoOptions.EnableImageTypes)) if (!string.IsNullOrWhiteSpace(hasDtoOptions.EnableImageTypes))
{
if (string.IsNullOrEmpty(hasDtoOptions.EnableImageTypes))
{
options.ImageTypes = Array.Empty<ImageType>();
}
else
{ {
options.ImageTypes = hasDtoOptions.EnableImageTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) options.ImageTypes = hasDtoOptions.EnableImageTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)) .Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true))
.ToArray(); .ToArray();
} }
} }
}
return options; return options;
} }

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -180,7 +181,7 @@ namespace MediaBrowser.Api
return ToOptimizedResult(filters); return ToOptimizedResult(filters);
} }
private QueryFiltersLegacy GetFilters(BaseItem[] items) private QueryFiltersLegacy GetFilters(IReadOnlyCollection<BaseItem> items)
{ {
var result = new QueryFiltersLegacy(); var result = new QueryFiltersLegacy();

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
@ -197,29 +198,27 @@ namespace MediaBrowser.Api.UserLibrary
request.ParentId = null; request.ParentId = null;
} }
var item = string.IsNullOrEmpty(request.ParentId) ? BaseItem item = null;
null :
_libraryManager.GetItemById(request.ParentId);
if (item == null) if (!string.IsNullOrEmpty(request.ParentId))
{ {
item = string.IsNullOrEmpty(request.ParentId) ? item = _libraryManager.GetItemById(request.ParentId);
user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder() :
_libraryManager.GetItemById(request.ParentId);
} }
// Default list type = children if (item == null)
{
item = _libraryManager.GetUserRootFolder();
}
var folder = item as Folder; Folder folder = item as Folder;
if (folder == null) if (folder == null)
{ {
folder = user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder(); folder = _libraryManager.GetUserRootFolder();
} }
var hasCollectionType = folder as IHasCollectionType; var hasCollectionType = folder as IHasCollectionType;
var isPlaylistQuery = (hasCollectionType != null && string.Equals(hasCollectionType.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)); if (hasCollectionType != null
&& string.Equals(hasCollectionType.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase))
if (isPlaylistQuery)
{ {
request.Recursive = true; request.Recursive = true;
request.IncludeItemTypes = "Playlist"; request.IncludeItemTypes = "Playlist";
@ -235,20 +234,12 @@ namespace MediaBrowser.Api.UserLibrary
}; };
} }
if (request.Recursive || !string.IsNullOrEmpty(request.Ids) || user == null) if (request.Recursive || !string.IsNullOrEmpty(request.Ids) || !(item is UserRootFolder))
{
return folder.GetItems(GetItemsQuery(request, dtoOptions, user));
}
var userRoot = item as UserRootFolder;
if (userRoot == null)
{ {
return folder.GetItems(GetItemsQuery(request, dtoOptions, user)); return folder.GetItems(GetItemsQuery(request, dtoOptions, user));
} }
var itemsArray = folder.GetChildren(user, true).ToArray(); var itemsArray = folder.GetChildren(user, true).ToArray();
return new QueryResult<BaseItem> return new QueryResult<BaseItem>
{ {
Items = itemsArray, Items = itemsArray,

@ -36,9 +36,7 @@ namespace MediaBrowser.Controller.Dto
.ToArray(); .ToArray();
public bool ContainsField(ItemFields field) public bool ContainsField(ItemFields field)
{ => Fields.Contains(field);
return AllItemFields.Contains(field);
}
public DtoOptions(bool allFields) public DtoOptions(bool allFields)
{ {
@ -47,15 +45,7 @@ namespace MediaBrowser.Controller.Dto
EnableUserData = true; EnableUserData = true;
AddCurrentProgram = true; AddCurrentProgram = true;
if (allFields) Fields = allFields ? AllItemFields : Array.Empty<ItemFields>();
{
Fields = AllItemFields;
}
else
{
Fields = new ItemFields[] { };
}
ImageTypes = AllImageTypes; ImageTypes = AllImageTypes;
} }

@ -57,9 +57,7 @@ namespace MediaBrowser.Controller.Dto
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="user">The user.</param> /// <param name="user">The user.</param>
/// <param name="owner">The owner.</param> /// <param name="owner">The owner.</param>
BaseItemDto[] GetBaseItemDtos(BaseItem[] items, DtoOptions options, User user = null, BaseItem owner = null); BaseItemDto[] GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null);
BaseItemDto[] GetBaseItemDtos(List<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null);
/// <summary> /// <summary>
/// Gets the item by name dto. /// Gets the item by name dto.

@ -810,37 +810,19 @@ namespace MediaBrowser.Controller.Entities
{ {
if (query.ItemIds.Length > 0) if (query.ItemIds.Length > 0)
{ {
var result = LibraryManager.GetItemsResult(query); return LibraryManager.GetItemsResult(query);
if (query.OrderBy.Length == 0)
{
var ids = query.ItemIds.ToList();
// Try to preserve order
result.Items = result.Items.OrderBy(i => ids.IndexOf(i.Id)).ToArray();
}
return result;
} }
return GetItemsInternal(query); return GetItemsInternal(query);
} }
public BaseItem[] GetItemList(InternalItemsQuery query) public IReadOnlyList<BaseItem> GetItemList(InternalItemsQuery query)
{ {
query.EnableTotalRecordCount = false; query.EnableTotalRecordCount = false;
if (query.ItemIds.Length > 0) if (query.ItemIds.Length > 0)
{ {
var result = LibraryManager.GetItemList(query); return LibraryManager.GetItemList(query);
if (query.OrderBy.Length == 0)
{
var ids = query.ItemIds.ToList();
// Try to preserve order
return result.OrderBy(i => ids.IndexOf(i.Id)).ToArray();
}
return result.ToArray();
} }
return GetItemsInternal(query).Items; return GetItemsInternal(query).Items;

Loading…
Cancel
Save