From a60cb280a3d31ba19ffb3a94cf83ef300a7473b7 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Thu, 20 Jan 2022 08:46:17 -0700 Subject: [PATCH] Properly populate QueryResult --- Emby.Dlna/ContentDirectory/ControlHandler.cs | 104 +++++++++--------- .../Channels/ChannelManager.cs | 36 +++--- .../Data/SqliteItemRepository.cs | 21 ++-- .../Library/LibraryManager.cs | 16 +-- .../Library/SearchEngine.cs | 10 +- .../LiveTv/LiveTvManager.cs | 60 ++++------ .../TV/TVSeriesManager.cs | 9 +- Jellyfin.Api/Controllers/ApiKeyController.cs | 6 +- Jellyfin.Api/Controllers/ArtistsController.cs | 18 ++- .../Controllers/InstantMixController.cs | 10 +- Jellyfin.Api/Controllers/ItemsController.cs | 17 +-- Jellyfin.Api/Controllers/LibraryController.cs | 18 +-- Jellyfin.Api/Controllers/LiveTvController.cs | 15 +-- Jellyfin.Api/Controllers/PersonsController.cs | 6 +- .../Controllers/PlaylistsController.cs | 9 +- .../Controllers/SuggestionsController.cs | 9 +- Jellyfin.Api/Controllers/TvShowsController.cs | 33 +++--- .../Controllers/UserLibraryController.cs | 6 +- .../Controllers/UserViewsController.cs | 6 +- Jellyfin.Api/Controllers/VideosController.cs | 7 +- Jellyfin.Api/Controllers/YearsController.cs | 8 +- Jellyfin.Api/Helpers/RequestHelpers.cs | 9 +- .../Activity/ActivityManager.cs | 11 +- .../Devices/DeviceManager.cs | 20 ++-- MediaBrowser.Controller/Entities/Folder.cs | 9 +- .../Entities/UserViewBuilder.cs | 26 +---- MediaBrowser.Model/Querying/QueryResult.cs | 7 ++ 27 files changed, 209 insertions(+), 297 deletions(-) diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.cs index 0cd1a0daf..57170bb31 100644 --- a/Emby.Dlna/ContentDirectory/ControlHandler.cs +++ b/Emby.Dlna/ContentDirectory/ControlHandler.cs @@ -619,7 +619,7 @@ namespace Emby.Dlna.ContentDirectory var queryResult = folder.GetItems(query); - return ToResult(queryResult); + return ToResult(startIndex, queryResult); } /// @@ -642,7 +642,7 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(startIndex, result); } /// @@ -707,11 +707,10 @@ namespace Emby.Dlna.ContentDirectory serverItems = serverItems[..limit.Value]; } - return new QueryResult - { - Items = serverItems, - TotalRecordCount = serverItems.Length - }; + return new QueryResult( + startIndex, + serverItems.Length, + serverItems); } /// @@ -764,11 +763,10 @@ namespace Emby.Dlna.ContentDirectory array = array[..limit.Value]; } - return new QueryResult - { - Items = array, - TotalRecordCount = array.Length - }; + return new QueryResult( + startIndex, + array.Length, + array); } /// @@ -790,11 +788,10 @@ namespace Emby.Dlna.ContentDirectory .Select(i => new ServerItem(i, StubType.Folder)) .ToArray(); - return new QueryResult - { - Items = items, - TotalRecordCount = totalRecordCount - }; + return new QueryResult( + startIndex, + totalRecordCount, + items); } /// @@ -850,11 +847,10 @@ namespace Emby.Dlna.ContentDirectory serverItems = serverItems[..limit.Value]; } - return new QueryResult - { - Items = serverItems, - TotalRecordCount = serverItems.Length - }; + return new QueryResult( + startIndex, + serverItems.Length, + serverItems); } /// @@ -879,7 +875,7 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(query.StartIndex, result); } /// @@ -894,7 +890,7 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(query.StartIndex, result); } /// @@ -914,7 +910,7 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(query.StartIndex, result); } /// @@ -931,7 +927,7 @@ namespace Emby.Dlna.ContentDirectory query.AncestorIds = new[] { parent.Id }; var genresResult = _libraryManager.GetGenres(query); - return ToResult(genresResult); + return ToResult(query.StartIndex, genresResult); } /// @@ -947,7 +943,7 @@ namespace Emby.Dlna.ContentDirectory query.AncestorIds = new[] { parent.Id }; var genresResult = _libraryManager.GetMusicGenres(query); - return ToResult(genresResult); + return ToResult(query.StartIndex, genresResult); } /// @@ -963,7 +959,7 @@ namespace Emby.Dlna.ContentDirectory query.AncestorIds = new[] { parent.Id }; var artists = _libraryManager.GetAlbumArtists(query); - return ToResult(artists); + return ToResult(query.StartIndex, artists); } /// @@ -978,7 +974,7 @@ namespace Emby.Dlna.ContentDirectory query.OrderBy = Array.Empty<(string, SortOrder)>(); query.AncestorIds = new[] { parent.Id }; var artists = _libraryManager.GetArtists(query); - return ToResult(artists); + return ToResult(query.StartIndex, artists); } /// @@ -994,7 +990,7 @@ namespace Emby.Dlna.ContentDirectory query.AncestorIds = new[] { parent.Id }; query.IsFavorite = true; var artists = _libraryManager.GetArtists(query); - return ToResult(artists); + return ToResult(query.StartIndex, artists); } /// @@ -1010,7 +1006,7 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(query.StartIndex, result); } /// @@ -1034,7 +1030,7 @@ namespace Emby.Dlna.ContentDirectory new[] { parent }, query.DtoOptions); - return ToResult(result); + return ToResult(query.StartIndex, result); } /// @@ -1060,7 +1056,7 @@ namespace Emby.Dlna.ContentDirectory }, query.DtoOptions).Select(i => i.Item1 ?? i.Item2.FirstOrDefault()).Where(i => i != null).ToArray(); - return ToResult(items); + return ToResult(query.StartIndex, items); } /// @@ -1087,7 +1083,7 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(startIndex, result); } /// @@ -1118,7 +1114,7 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(startIndex, result); } /// @@ -1145,33 +1141,34 @@ namespace Emby.Dlna.ContentDirectory var result = _libraryManager.GetItemsResult(query); - return ToResult(result); + return ToResult(startIndex, result); } /// /// Converts into a . /// + /// The start index. /// An array of . /// A . - private static QueryResult ToResult(IReadOnlyCollection result) + private static QueryResult ToResult(int? startIndex, IReadOnlyCollection result) { var serverItems = result .Select(i => new ServerItem(i, null)) .ToArray(); - return new QueryResult - { - TotalRecordCount = result.Count, - Items = serverItems - }; + return new QueryResult( + startIndex, + result.Count, + serverItems); } /// /// Converts a to a . /// + /// The index the result started at. /// A . /// The . - private static QueryResult ToResult(QueryResult result) + private static QueryResult ToResult(int? startIndex, QueryResult result) { var length = result.Items.Count; var serverItems = new ServerItem[length]; @@ -1180,19 +1177,19 @@ namespace Emby.Dlna.ContentDirectory serverItems[i] = new ServerItem(result.Items[i], null); } - return new QueryResult - { - TotalRecordCount = result.TotalRecordCount, - Items = serverItems - }; + return new QueryResult( + startIndex, + result.TotalRecordCount, + serverItems); } /// /// Converts a query result to a . /// + /// The start index. /// A . /// The . - private static QueryResult ToResult(QueryResult<(BaseItem Item, ItemCounts ItemCounts)> result) + private static QueryResult ToResult(int? startIndex, QueryResult<(BaseItem Item, ItemCounts ItemCounts)> result) { var length = result.Items.Count; var serverItems = new ServerItem[length]; @@ -1201,11 +1198,10 @@ namespace Emby.Dlna.ContentDirectory serverItems[i] = new ServerItem(result.Items[i].Item, null); } - return new QueryResult - { - TotalRecordCount = result.TotalRecordCount, - Items = serverItems - }; + return new QueryResult( + startIndex, + result.TotalRecordCount, + serverItems); } /// diff --git a/Emby.Server.Implementations/Channels/ChannelManager.cs b/Emby.Server.Implementations/Channels/ChannelManager.cs index 43c8a451b..548ebc3fc 100644 --- a/Emby.Server.Implementations/Channels/ChannelManager.cs +++ b/Emby.Server.Implementations/Channels/ChannelManager.cs @@ -264,11 +264,10 @@ namespace Emby.Server.Implementations.Channels } } - return new QueryResult - { - Items = all, - TotalRecordCount = totalCount - }; + return new QueryResult( + query.StartIndex, + totalCount, + all); } /// @@ -285,11 +284,10 @@ namespace Emby.Server.Implementations.Channels // TODO Fix The co-variant conversion (internalResult.Items) between Folder[] and BaseItem[], this can generate runtime issues. var returnItems = _dtoService.GetBaseItemDtos(internalResult.Items, dtoOptions, user); - var result = new QueryResult - { - Items = returnItems, - TotalRecordCount = internalResult.TotalRecordCount - }; + var result = new QueryResult( + query.StartIndex, + internalResult.TotalRecordCount, + returnItems); return result; } @@ -620,11 +618,10 @@ namespace Emby.Server.Implementations.Channels var returnItems = _dtoService.GetBaseItemDtos(items, query.DtoOptions, query.User); - var result = new QueryResult - { - Items = returnItems, - TotalRecordCount = totalRecordCount - }; + var result = new QueryResult( + query.StartIndex, + totalRecordCount, + returnItems); return result; } @@ -786,11 +783,10 @@ namespace Emby.Server.Implementations.Channels var returnItems = _dtoService.GetBaseItemDtos(internalResult.Items, query.DtoOptions, query.User); - var result = new QueryResult - { - Items = returnItems, - TotalRecordCount = internalResult.TotalRecordCount - }; + var result = new QueryResult( + query.StartIndex, + internalResult.TotalRecordCount, + returnItems); return result; } diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index 5ab9e02fe..1da9b4650 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -2810,11 +2810,10 @@ namespace Emby.Server.Implementations.Data if (!query.EnableTotalRecordCount || (!query.Limit.HasValue && (query.StartIndex ?? 0) == 0)) { var returnList = GetItemList(query); - return new QueryResult - { - Items = returnList, - TotalRecordCount = returnList.Count - }; + return new QueryResult( + query.StartIndex, + returnList.Count, + returnList); } var now = DateTime.UtcNow; @@ -2978,6 +2977,7 @@ namespace Emby.Server.Implementations.Data ReadTransactionMode); } + result.StartIndex = query.StartIndex ?? 0; result.Items = list; return result; } @@ -3265,11 +3265,10 @@ namespace Emby.Server.Implementations.Data if (!query.EnableTotalRecordCount || (!query.Limit.HasValue && (query.StartIndex ?? 0) == 0)) { var returnList = GetItemIdsList(query); - return new QueryResult - { - Items = returnList, - TotalRecordCount = returnList.Count - }; + return new QueryResult( + query.StartIndex, + returnList.Count, + returnList); } var now = DateTime.UtcNow; @@ -3395,6 +3394,7 @@ namespace Emby.Server.Implementations.Data LogQueryTime("GetItemIds", commandText, now); + result.StartIndex = query.StartIndex ?? 0; result.Items = list; return result; } @@ -5599,6 +5599,7 @@ AND Type = @InternalPersonType)"); result.TotalRecordCount = list.Count; } + result.StartIndex = query.StartIndex ?? 0; result.Items = list; return result; diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index bd0c178fd..262d9fed7 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -1360,10 +1360,10 @@ namespace Emby.Server.Implementations.Library return _itemRepository.GetItems(query); } - return new QueryResult - { - Items = _itemRepository.GetItemList(query) - }; + return new QueryResult( + query.StartIndex, + null, + _itemRepository.GetItemList(query)); } public List GetItemIds(InternalItemsQuery query) @@ -1493,10 +1493,10 @@ namespace Emby.Server.Implementations.Library return _itemRepository.GetItems(query); } - return new QueryResult - { - Items = _itemRepository.GetItemList(query) - }; + return new QueryResult( + query.StartIndex, + null, + _itemRepository.GetItemList(query)); } private void SetTopParentIdsOrAncestors(InternalItemsQuery query, List parents) diff --git a/Emby.Server.Implementations/Library/SearchEngine.cs b/Emby.Server.Implementations/Library/SearchEngine.cs index 55911933a..70d9cbc98 100644 --- a/Emby.Server.Implementations/Library/SearchEngine.cs +++ b/Emby.Server.Implementations/Library/SearchEngine.cs @@ -48,12 +48,10 @@ namespace Emby.Server.Implementations.Library results = results.GetRange(0, Math.Min(query.Limit.Value, results.Count)); } - return new QueryResult - { - TotalRecordCount = totalRecordCount, - - Items = results - }; + return new QueryResult( + query.StartIndex, + totalRecordCount, + results); } private static void AddIfMissing(List list, BaseItemKind value) diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index aa3598c8b..8d0f18d9b 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -857,11 +857,10 @@ namespace Emby.Server.Implementations.LiveTv var returnArray = _dtoService.GetBaseItemDtos(queryResult.Items, options, user); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = queryResult.TotalRecordCount - }; + return new QueryResult( + query.StartIndex, + queryResult.TotalRecordCount, + returnArray); } public QueryResult GetRecommendedProgramsInternal(InternalItemsQuery query, DtoOptions options, CancellationToken cancellationToken) @@ -910,11 +909,10 @@ namespace Emby.Server.Implementations.LiveTv programs = programs.Take(query.Limit.Value); } - return new QueryResult - { - Items = programs.ToArray(), - TotalRecordCount = totalCount - }; + return new QueryResult( + query.StartIndex, + totalCount, + programs.ToArray()); } public QueryResult GetRecommendedPrograms(InternalItemsQuery query, DtoOptions options, CancellationToken cancellationToken) @@ -928,11 +926,10 @@ namespace Emby.Server.Implementations.LiveTv var internalResult = GetRecommendedProgramsInternal(query, options, cancellationToken); - return new QueryResult - { - Items = _dtoService.GetBaseItemDtos(internalResult.Items, options, query.User), - TotalRecordCount = internalResult.TotalRecordCount - }; + return new QueryResult( + query.StartIndex, + internalResult.TotalRecordCount, + _dtoService.GetBaseItemDtos(internalResult.Items, options, query.User)); } private int GetRecommendationScore(LiveTvProgram program, User user, bool factorChannelWatchCount) @@ -1541,11 +1538,10 @@ namespace Emby.Server.Implementations.LiveTv var returnArray = _dtoService.GetBaseItemDtos(internalResult.Items, options, user); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = internalResult.TotalRecordCount - }; + return new QueryResult( + query.StartIndex, + internalResult.TotalRecordCount, + returnArray); } private async Task> GetTimersInternal(TimerQuery query, CancellationToken cancellationToken) @@ -1615,11 +1611,7 @@ namespace Emby.Server.Implementations.LiveTv .OrderBy(i => i.StartDate) .ToArray(); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = returnArray.Length - }; + return new QueryResult(returnArray); } public async Task> GetTimers(TimerQuery query, CancellationToken cancellationToken) @@ -1701,11 +1693,7 @@ namespace Emby.Server.Implementations.LiveTv .OrderBy(i => i.StartDate) .ToArray(); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = returnArray.Length - }; + return new QueryResult(returnArray); } public async Task CancelTimer(string id) @@ -1801,11 +1789,7 @@ namespace Emby.Server.Implementations.LiveTv .Select(i => i.Item1) .ToArray(); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = returnArray.Length - }; + return new QueryResult(returnArray); } public async Task> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken) @@ -1855,11 +1839,7 @@ namespace Emby.Server.Implementations.LiveTv }) .ToArray(); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = returnArray.Length - }; + return new QueryResult(returnArray); } public BaseItem GetLiveTvChannel(TimerInfo timer, ILiveTvService service) diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.cs index c994ffc90..a18af27f3 100644 --- a/Emby.Server.Implementations/TV/TVSeriesManager.cs +++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs @@ -304,11 +304,10 @@ namespace Emby.Server.Implementations.TV items = items.Take(query.Limit.Value); } - return new QueryResult - { - TotalRecordCount = totalCount, - Items = items.ToArray() - }; + return new QueryResult( + query.StartIndex, + totalCount, + items.ToArray()); } } } diff --git a/Jellyfin.Api/Controllers/ApiKeyController.cs b/Jellyfin.Api/Controllers/ApiKeyController.cs index 8e0332d3e..593846adc 100644 --- a/Jellyfin.Api/Controllers/ApiKeyController.cs +++ b/Jellyfin.Api/Controllers/ApiKeyController.cs @@ -38,11 +38,7 @@ namespace Jellyfin.Api.Controllers { var keys = await _authenticationManager.GetApiKeys(); - return new QueryResult - { - Items = keys, - TotalRecordCount = keys.Count - }; + return new QueryResult(keys); } /// diff --git a/Jellyfin.Api/Controllers/ArtistsController.cs b/Jellyfin.Api/Controllers/ArtistsController.cs index 3df975563..b54825775 100644 --- a/Jellyfin.Api/Controllers/ArtistsController.cs +++ b/Jellyfin.Api/Controllers/ArtistsController.cs @@ -243,11 +243,10 @@ namespace Jellyfin.Api.Controllers return dto; }); - return new QueryResult - { - Items = dtos.ToArray(), - TotalRecordCount = result.TotalRecordCount - }; + return new QueryResult( + query.StartIndex, + result.TotalRecordCount, + dtos.ToArray()); } /// @@ -447,11 +446,10 @@ namespace Jellyfin.Api.Controllers return dto; }); - return new QueryResult - { - Items = dtos.ToArray(), - TotalRecordCount = result.TotalRecordCount - }; + return new QueryResult( + query.StartIndex, + result.TotalRecordCount, + dtos.ToArray()); } /// diff --git a/Jellyfin.Api/Controllers/InstantMixController.cs b/Jellyfin.Api/Controllers/InstantMixController.cs index a6c2e07c9..e9d48b624 100644 --- a/Jellyfin.Api/Controllers/InstantMixController.cs +++ b/Jellyfin.Api/Controllers/InstantMixController.cs @@ -341,10 +341,7 @@ namespace Jellyfin.Api.Controllers { var list = items; - var result = new QueryResult - { - TotalRecordCount = list.Count - }; + var totalCount = list.Count; if (limit.HasValue && limit < list.Count) { @@ -353,7 +350,10 @@ namespace Jellyfin.Api.Controllers var returnList = _dtoService.GetBaseItemDtos(list, dtoOptions, user); - result.Items = returnList; + var result = new QueryResult( + 0, + totalCount, + returnList); return result; } diff --git a/Jellyfin.Api/Controllers/ItemsController.cs b/Jellyfin.Api/Controllers/ItemsController.cs index f8192955e..dc7af0a20 100644 --- a/Jellyfin.Api/Controllers/ItemsController.cs +++ b/Jellyfin.Api/Controllers/ItemsController.cs @@ -491,10 +491,13 @@ namespace Jellyfin.Api.Controllers else { var itemsArray = folder.GetChildren(user, true); - result = new QueryResult { Items = itemsArray, TotalRecordCount = itemsArray.Count, StartIndex = 0 }; + result = new QueryResult(itemsArray); } - return new QueryResult { StartIndex = startIndex.GetValueOrDefault(), TotalRecordCount = result.TotalRecordCount, Items = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user) }; + return new QueryResult( + startIndex, + result.TotalRecordCount, + _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user)); } /// @@ -836,12 +839,10 @@ namespace Jellyfin.Api.Controllers var returnItems = _dtoService.GetBaseItemDtos(itemsResult.Items, dtoOptions, user); - return new QueryResult - { - StartIndex = startIndex.GetValueOrDefault(), - TotalRecordCount = itemsResult.TotalRecordCount, - Items = returnItems - }; + return new QueryResult( + startIndex, + itemsResult.TotalRecordCount, + returnItems); } } } diff --git a/Jellyfin.Api/Controllers/LibraryController.cs b/Jellyfin.Api/Controllers/LibraryController.cs index f1b9c2f67..c65462ab5 100644 --- a/Jellyfin.Api/Controllers/LibraryController.cs +++ b/Jellyfin.Api/Controllers/LibraryController.cs @@ -506,13 +506,8 @@ namespace Jellyfin.Api.Controllers } var dtoOptions = new DtoOptions().AddClientFields(Request); - var result = new QueryResult - { - TotalRecordCount = items.Count, - Items = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions)).ToArray() - }; - - return result; + var resultArray = _dtoService.GetBaseItemDtos(items, dtoOptions); + return new QueryResult(resultArray); } /// @@ -759,11 +754,10 @@ namespace Jellyfin.Api.Controllers var returnList = _dtoService.GetBaseItemDtos(itemsResult, dtoOptions, user); - return new QueryResult - { - Items = returnList, - TotalRecordCount = itemsResult.Count - }; + return new QueryResult( + query.StartIndex, + itemsResult.Count, + returnList); } /// diff --git a/Jellyfin.Api/Controllers/LiveTvController.cs b/Jellyfin.Api/Controllers/LiveTvController.cs index 9e2ef8c60..4240bc3ff 100644 --- a/Jellyfin.Api/Controllers/LiveTvController.cs +++ b/Jellyfin.Api/Controllers/LiveTvController.cs @@ -193,11 +193,10 @@ namespace Jellyfin.Api.Controllers dtoOptions.AddCurrentProgram = addCurrentProgram; var returnArray = _dtoService.GetBaseItemDtos(channelResult.Items, dtoOptions, user); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = channelResult.TotalRecordCount - }; + return new QueryResult( + startIndex, + channelResult.TotalRecordCount, + returnArray); } /// @@ -390,11 +389,7 @@ namespace Jellyfin.Api.Controllers var returnArray = _dtoService.GetBaseItemDtos(folders, new DtoOptions(), user); - return new QueryResult - { - Items = returnArray, - TotalRecordCount = returnArray.Count - }; + return new QueryResult(returnArray); } /// diff --git a/Jellyfin.Api/Controllers/PersonsController.cs b/Jellyfin.Api/Controllers/PersonsController.cs index cb4894d77..ffc748a6e 100644 --- a/Jellyfin.Api/Controllers/PersonsController.cs +++ b/Jellyfin.Api/Controllers/PersonsController.cs @@ -101,11 +101,7 @@ namespace Jellyfin.Api.Controllers Limit = limit ?? 0 }); - return new QueryResult - { - Items = peopleItems.Select(person => _dtoService.GetItemByNameDto(person, dtoOptions, null, user)).ToArray(), - TotalRecordCount = peopleItems.Count - }; + return new QueryResult(peopleItems.Select(person => _dtoService.GetItemByNameDto(person, dtoOptions, null, user)).ToArray()); } /// diff --git a/Jellyfin.Api/Controllers/PlaylistsController.cs b/Jellyfin.Api/Controllers/PlaylistsController.cs index 1667d6ede..c18f1b427 100644 --- a/Jellyfin.Api/Controllers/PlaylistsController.cs +++ b/Jellyfin.Api/Controllers/PlaylistsController.cs @@ -208,11 +208,10 @@ namespace Jellyfin.Api.Controllers dtos[index].PlaylistItemId = items[index].Item1.Id; } - var result = new QueryResult - { - Items = dtos, - TotalRecordCount = count - }; + var result = new QueryResult( + startIndex, + count, + dtos); return result; } diff --git a/Jellyfin.Api/Controllers/SuggestionsController.cs b/Jellyfin.Api/Controllers/SuggestionsController.cs index af77c801f..73be26bb2 100644 --- a/Jellyfin.Api/Controllers/SuggestionsController.cs +++ b/Jellyfin.Api/Controllers/SuggestionsController.cs @@ -81,11 +81,10 @@ namespace Jellyfin.Api.Controllers var dtoList = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user); - return new QueryResult - { - TotalRecordCount = result.TotalRecordCount, - Items = dtoList - }; + return new QueryResult( + startIndex, + result.TotalRecordCount, + dtoList); } } } diff --git a/Jellyfin.Api/Controllers/TvShowsController.cs b/Jellyfin.Api/Controllers/TvShowsController.cs index e20bcd7a7..9425fe519 100644 --- a/Jellyfin.Api/Controllers/TvShowsController.cs +++ b/Jellyfin.Api/Controllers/TvShowsController.cs @@ -110,11 +110,10 @@ namespace Jellyfin.Api.Controllers var returnItems = _dtoService.GetBaseItemDtos(result.Items, options, user); - return new QueryResult - { - TotalRecordCount = result.TotalRecordCount, - Items = returnItems - }; + return new QueryResult( + startIndex, + result.TotalRecordCount, + returnItems); } /// @@ -169,11 +168,10 @@ namespace Jellyfin.Api.Controllers var returnItems = _dtoService.GetBaseItemDtos(itemsResult, options, user); - return new QueryResult - { - TotalRecordCount = itemsResult.Count, - Items = returnItems - }; + return new QueryResult( + startIndex, + itemsResult.Count, + returnItems); } /// @@ -296,11 +294,10 @@ namespace Jellyfin.Api.Controllers var dtos = _dtoService.GetBaseItemDtos(returnItems, dtoOptions, user); - return new QueryResult - { - TotalRecordCount = episodes.Count, - Items = dtos - }; + return new QueryResult( + startIndex, + episodes.Count, + dtos); } /// @@ -354,11 +351,7 @@ namespace Jellyfin.Api.Controllers var returnItems = _dtoService.GetBaseItemDtos(seasons, dtoOptions, user); - return new QueryResult - { - TotalRecordCount = returnItems.Count, - Items = returnItems - }; + return new QueryResult(returnItems); } /// diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs index 90cb4a74a..008d2f176 100644 --- a/Jellyfin.Api/Controllers/UserLibraryController.cs +++ b/Jellyfin.Api/Controllers/UserLibraryController.cs @@ -124,11 +124,7 @@ namespace Jellyfin.Api.Controllers var dtoOptions = new DtoOptions().AddClientFields(Request); var dtos = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray(); - return new QueryResult - { - Items = dtos, - TotalRecordCount = dtos.Length - }; + return new QueryResult(dtos); } /// diff --git a/Jellyfin.Api/Controllers/UserViewsController.cs b/Jellyfin.Api/Controllers/UserViewsController.cs index 3d27371f6..04171da8a 100644 --- a/Jellyfin.Api/Controllers/UserViewsController.cs +++ b/Jellyfin.Api/Controllers/UserViewsController.cs @@ -108,11 +108,7 @@ namespace Jellyfin.Api.Controllers var dtos = folders.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)) .ToArray(); - return new QueryResult - { - Items = dtos, - TotalRecordCount = dtos.Length - }; + return new QueryResult(dtos); } /// diff --git a/Jellyfin.Api/Controllers/VideosController.cs b/Jellyfin.Api/Controllers/VideosController.cs index 3c079a71d..89b150598 100644 --- a/Jellyfin.Api/Controllers/VideosController.cs +++ b/Jellyfin.Api/Controllers/VideosController.cs @@ -134,12 +134,7 @@ namespace Jellyfin.Api.Controllers items = Array.Empty(); } - var result = new QueryResult - { - Items = items, - TotalRecordCount = items.Length - }; - + var result = new QueryResult(items); return result; } diff --git a/Jellyfin.Api/Controllers/YearsController.cs b/Jellyfin.Api/Controllers/YearsController.cs index 8be6fd1b5..bac77d43b 100644 --- a/Jellyfin.Api/Controllers/YearsController.cs +++ b/Jellyfin.Api/Controllers/YearsController.cs @@ -136,8 +136,6 @@ namespace Jellyfin.Api.Controllers IEnumerable ibnItems = ibnItemsArray; - var result = new QueryResult { TotalRecordCount = ibnItemsArray.Count }; - if (startIndex.HasValue || limit.HasValue) { if (startIndex.HasValue) @@ -155,8 +153,10 @@ namespace Jellyfin.Api.Controllers var dtos = tuples.Select(i => _dtoService.GetItemByNameDto(i.Item1, dtoOptions, i.Item2, user)); - result.Items = dtos.Where(i => i != null).ToArray(); - + var result = new QueryResult( + startIndex, + ibnItemsArray.Count, + dtos.Where(i => i != null).ToArray()); return result; } diff --git a/Jellyfin.Api/Helpers/RequestHelpers.cs b/Jellyfin.Api/Helpers/RequestHelpers.cs index 2cfd36d00..20427d7fa 100644 --- a/Jellyfin.Api/Helpers/RequestHelpers.cs +++ b/Jellyfin.Api/Helpers/RequestHelpers.cs @@ -131,11 +131,10 @@ namespace Jellyfin.Api.Helpers return dto; }); - return new QueryResult - { - Items = dtos.ToArray(), - TotalRecordCount = result.TotalRecordCount - }; + return new QueryResult( + result.StartIndex, + result.TotalRecordCount, + dtos.ToArray()); } } } diff --git a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs index ba2c8b54f..4447b212d 100644 --- a/Jellyfin.Server.Implementations/Activity/ActivityManager.cs +++ b/Jellyfin.Server.Implementations/Activity/ActivityManager.cs @@ -59,17 +59,16 @@ namespace Jellyfin.Server.Implementations.Activity entries = entries.Where(entry => entry.UserId != Guid.Empty == query.HasUserId.Value ); } - return new QueryResult - { - Items = await entries + return new QueryResult( + query.Skip, + await entries.CountAsync().ConfigureAwait(false), + await entries .Skip(query.Skip ?? 0) .Take(query.Limit ?? 100) .AsAsyncEnumerable() .Select(ConvertToOldModel) .ToListAsync() - .ConfigureAwait(false), - TotalRecordCount = await entries.CountAsync().ConfigureAwait(false) - }; + .ConfigureAwait(false)); } /// diff --git a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs index 6c77421c7..b5fc96079 100644 --- a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs +++ b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs @@ -145,12 +145,10 @@ namespace Jellyfin.Server.Implementations.Devices devices = devices.Take(query.Limit.Value); } - return new QueryResult - { - Items = await devices.ToListAsync().ConfigureAwait(false), - StartIndex = query.Skip ?? 0, - TotalRecordCount = count - }; + return new QueryResult( + query.Skip, + count, + await devices.ToListAsync().ConfigureAwait(false)); } /// @@ -158,12 +156,10 @@ namespace Jellyfin.Server.Implementations.Devices { var devices = await GetDevices(query).ConfigureAwait(false); - return new QueryResult - { - Items = devices.Items.Select(device => ToDeviceInfo(device)).ToList(), - StartIndex = devices.StartIndex, - TotalRecordCount = devices.TotalRecordCount - }; + return new QueryResult( + devices.StartIndex, + devices.TotalRecordCount, + devices.Items.Select(device => ToDeviceInfo(device)).ToList()); } /// diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 55551e70e..79ffddc00 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -783,11 +783,10 @@ namespace MediaBrowser.Controller.Entities returnItems = returnItems.Skip(startIndex.Value); } - return new QueryResult - { - TotalRecordCount = totalCount, - Items = returnItems.ToArray() - }; + return new QueryResult( + query.StartIndex, + totalCount, + returnItems.ToArray()); } private bool RequiresPostFiltering2(InternalItemsQuery query) diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index fe44f1169..279206da4 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -238,12 +238,7 @@ namespace MediaBrowser.Controller.Entities private QueryResult ConvertToResult(List items) { - var arr = items.ToArray(); - return new QueryResult - { - Items = arr, - TotalRecordCount = arr.Length - }; + return new QueryResult(items); } private QueryResult GetMovieGenres(Folder parent, User user, InternalItemsQuery query) @@ -414,16 +409,6 @@ namespace MediaBrowser.Controller.Entities return _libraryManager.GetItemsResult(query); } - private QueryResult GetResult(QueryResult result) - where T : BaseItem - { - return new QueryResult - { - Items = result.Items, // TODO Fix The co-variant conversion between T[] and BaseItem[], this can generate runtime issues if T is not BaseItem. - TotalRecordCount = result.TotalRecordCount - }; - } - private QueryResult GetResult( IEnumerable items, InternalItemsQuery query) @@ -483,11 +468,10 @@ namespace MediaBrowser.Controller.Entities itemsArray = itemsArray.Skip(query.StartIndex.Value).ToArray(); } - return new QueryResult - { - TotalRecordCount = totalCount, - Items = itemsArray - }; + return new QueryResult( + query.StartIndex, + totalCount, + itemsArray); } public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager) diff --git a/MediaBrowser.Model/Querying/QueryResult.cs b/MediaBrowser.Model/Querying/QueryResult.cs index 8ce794800..ea843f34c 100644 --- a/MediaBrowser.Model/Querying/QueryResult.cs +++ b/MediaBrowser.Model/Querying/QueryResult.cs @@ -19,6 +19,13 @@ namespace MediaBrowser.Model.Querying TotalRecordCount = items.Count; } + public QueryResult(int? startIndex, int? totalRecordCount, IReadOnlyList items) + { + StartIndex = startIndex ?? 0; + TotalRecordCount = totalRecordCount ?? items.Count; + Items = items; + } + /// /// Gets or sets the items. ///