Properly populate QueryResult

This commit is contained in:
Cody Robibero 2022-01-20 08:46:17 -07:00
parent cd4587b43f
commit a60cb280a3
27 changed files with 209 additions and 297 deletions

View File

@ -619,7 +619,7 @@ namespace Emby.Dlna.ContentDirectory
var queryResult = folder.GetItems(query);
return ToResult(queryResult);
return ToResult(startIndex, queryResult);
}
/// <summary>
@ -642,7 +642,7 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(startIndex, result);
}
/// <summary>
@ -707,11 +707,10 @@ namespace Emby.Dlna.ContentDirectory
serverItems = serverItems[..limit.Value];
}
return new QueryResult<ServerItem>
{
Items = serverItems,
TotalRecordCount = serverItems.Length
};
return new QueryResult<ServerItem>(
startIndex,
serverItems.Length,
serverItems);
}
/// <summary>
@ -764,11 +763,10 @@ namespace Emby.Dlna.ContentDirectory
array = array[..limit.Value];
}
return new QueryResult<ServerItem>
{
Items = array,
TotalRecordCount = array.Length
};
return new QueryResult<ServerItem>(
startIndex,
array.Length,
array);
}
/// <summary>
@ -790,11 +788,10 @@ namespace Emby.Dlna.ContentDirectory
.Select(i => new ServerItem(i, StubType.Folder))
.ToArray();
return new QueryResult<ServerItem>
{
Items = items,
TotalRecordCount = totalRecordCount
};
return new QueryResult<ServerItem>(
startIndex,
totalRecordCount,
items);
}
/// <summary>
@ -850,11 +847,10 @@ namespace Emby.Dlna.ContentDirectory
serverItems = serverItems[..limit.Value];
}
return new QueryResult<ServerItem>
{
Items = serverItems,
TotalRecordCount = serverItems.Length
};
return new QueryResult<ServerItem>(
startIndex,
serverItems.Length,
serverItems);
}
/// <summary>
@ -879,7 +875,7 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(query.StartIndex, result);
}
/// <summary>
@ -894,7 +890,7 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(query.StartIndex, result);
}
/// <summary>
@ -914,7 +910,7 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(query.StartIndex, result);
}
/// <summary>
@ -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);
}
/// <summary>
@ -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);
}
/// <summary>
@ -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);
}
/// <summary>
@ -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);
}
/// <summary>
@ -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);
}
/// <summary>
@ -1010,7 +1006,7 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(query.StartIndex, result);
}
/// <summary>
@ -1034,7 +1030,7 @@ namespace Emby.Dlna.ContentDirectory
new[] { parent },
query.DtoOptions);
return ToResult(result);
return ToResult(query.StartIndex, result);
}
/// <summary>
@ -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);
}
/// <summary>
@ -1087,7 +1083,7 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(startIndex, result);
}
/// <summary>
@ -1118,7 +1114,7 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(startIndex, result);
}
/// <summary>
@ -1145,33 +1141,34 @@ namespace Emby.Dlna.ContentDirectory
var result = _libraryManager.GetItemsResult(query);
return ToResult(result);
return ToResult(startIndex, result);
}
/// <summary>
/// Converts <see cref="IReadOnlyCollection{BaseItem}"/> into a <see cref="QueryResult{ServerItem}"/>.
/// </summary>
/// <param name="startIndex">The start index.</param>
/// <param name="result">An array of <see cref="BaseItem"/>.</param>
/// <returns>A <see cref="QueryResult{ServerItem}"/>.</returns>
private static QueryResult<ServerItem> ToResult(IReadOnlyCollection<BaseItem> result)
private static QueryResult<ServerItem> ToResult(int? startIndex, IReadOnlyCollection<BaseItem> result)
{
var serverItems = result
.Select(i => new ServerItem(i, null))
.ToArray();
return new QueryResult<ServerItem>
{
TotalRecordCount = result.Count,
Items = serverItems
};
return new QueryResult<ServerItem>(
startIndex,
result.Count,
serverItems);
}
/// <summary>
/// Converts a <see cref="QueryResult{BaseItem}"/> to a <see cref="QueryResult{ServerItem}"/>.
/// </summary>
/// <param name="startIndex">The index the result started at.</param>
/// <param name="result">A <see cref="QueryResult{BaseItem}"/>.</param>
/// <returns>The <see cref="QueryResult{ServerItem}"/>.</returns>
private static QueryResult<ServerItem> ToResult(QueryResult<BaseItem> result)
private static QueryResult<ServerItem> ToResult(int? startIndex, QueryResult<BaseItem> 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<ServerItem>
{
TotalRecordCount = result.TotalRecordCount,
Items = serverItems
};
return new QueryResult<ServerItem>(
startIndex,
result.TotalRecordCount,
serverItems);
}
/// <summary>
/// Converts a query result to a <see cref="QueryResult{ServerItem}"/>.
/// </summary>
/// <param name="startIndex">The start index.</param>
/// <param name="result">A <see cref="QueryResult{BaseItem}"/>.</param>
/// <returns>The <see cref="QueryResult{ServerItem}"/>.</returns>
private static QueryResult<ServerItem> ToResult(QueryResult<(BaseItem Item, ItemCounts ItemCounts)> result)
private static QueryResult<ServerItem> 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<ServerItem>
{
TotalRecordCount = result.TotalRecordCount,
Items = serverItems
};
return new QueryResult<ServerItem>(
startIndex,
result.TotalRecordCount,
serverItems);
}
/// <summary>

View File

@ -264,11 +264,10 @@ namespace Emby.Server.Implementations.Channels
}
}
return new QueryResult<Channel>
{
Items = all,
TotalRecordCount = totalCount
};
return new QueryResult<Channel>(
query.StartIndex,
totalCount,
all);
}
/// <inheritdoc />
@ -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<BaseItemDto>
{
Items = returnItems,
TotalRecordCount = internalResult.TotalRecordCount
};
var result = new QueryResult<BaseItemDto>(
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<BaseItemDto>
{
Items = returnItems,
TotalRecordCount = totalRecordCount
};
var result = new QueryResult<BaseItemDto>(
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<BaseItemDto>
{
Items = returnItems,
TotalRecordCount = internalResult.TotalRecordCount
};
var result = new QueryResult<BaseItemDto>(
query.StartIndex,
internalResult.TotalRecordCount,
returnItems);
return result;
}

View File

@ -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<BaseItem>
{
Items = returnList,
TotalRecordCount = returnList.Count
};
return new QueryResult<BaseItem>(
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<Guid>
{
Items = returnList,
TotalRecordCount = returnList.Count
};
return new QueryResult<Guid>(
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;

View File

@ -1360,10 +1360,10 @@ namespace Emby.Server.Implementations.Library
return _itemRepository.GetItems(query);
}
return new QueryResult<BaseItem>
{
Items = _itemRepository.GetItemList(query)
};
return new QueryResult<BaseItem>(
query.StartIndex,
null,
_itemRepository.GetItemList(query));
}
public List<Guid> GetItemIds(InternalItemsQuery query)
@ -1493,10 +1493,10 @@ namespace Emby.Server.Implementations.Library
return _itemRepository.GetItems(query);
}
return new QueryResult<BaseItem>
{
Items = _itemRepository.GetItemList(query)
};
return new QueryResult<BaseItem>(
query.StartIndex,
null,
_itemRepository.GetItemList(query));
}
private void SetTopParentIdsOrAncestors(InternalItemsQuery query, List<BaseItem> parents)

View File

@ -48,12 +48,10 @@ namespace Emby.Server.Implementations.Library
results = results.GetRange(0, Math.Min(query.Limit.Value, results.Count));
}
return new QueryResult<SearchHintInfo>
{
TotalRecordCount = totalRecordCount,
Items = results
};
return new QueryResult<SearchHintInfo>(
query.StartIndex,
totalRecordCount,
results);
}
private static void AddIfMissing(List<BaseItemKind> list, BaseItemKind value)

View File

@ -857,11 +857,10 @@ namespace Emby.Server.Implementations.LiveTv
var returnArray = _dtoService.GetBaseItemDtos(queryResult.Items, options, user);
return new QueryResult<BaseItemDto>
{
Items = returnArray,
TotalRecordCount = queryResult.TotalRecordCount
};
return new QueryResult<BaseItemDto>(
query.StartIndex,
queryResult.TotalRecordCount,
returnArray);
}
public QueryResult<BaseItem> 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<BaseItem>
{
Items = programs.ToArray(),
TotalRecordCount = totalCount
};
return new QueryResult<BaseItem>(
query.StartIndex,
totalCount,
programs.ToArray());
}
public QueryResult<BaseItemDto> 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<BaseItemDto>
{
Items = _dtoService.GetBaseItemDtos(internalResult.Items, options, query.User),
TotalRecordCount = internalResult.TotalRecordCount
};
return new QueryResult<BaseItemDto>(
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<BaseItemDto>
{
Items = returnArray,
TotalRecordCount = internalResult.TotalRecordCount
};
return new QueryResult<BaseItemDto>(
query.StartIndex,
internalResult.TotalRecordCount,
returnArray);
}
private async Task<QueryResult<TimerInfo>> GetTimersInternal(TimerQuery query, CancellationToken cancellationToken)
@ -1615,11 +1611,7 @@ namespace Emby.Server.Implementations.LiveTv
.OrderBy(i => i.StartDate)
.ToArray();
return new QueryResult<TimerInfo>
{
Items = returnArray,
TotalRecordCount = returnArray.Length
};
return new QueryResult<TimerInfo>(returnArray);
}
public async Task<QueryResult<TimerInfoDto>> GetTimers(TimerQuery query, CancellationToken cancellationToken)
@ -1701,11 +1693,7 @@ namespace Emby.Server.Implementations.LiveTv
.OrderBy(i => i.StartDate)
.ToArray();
return new QueryResult<TimerInfoDto>
{
Items = returnArray,
TotalRecordCount = returnArray.Length
};
return new QueryResult<TimerInfoDto>(returnArray);
}
public async Task CancelTimer(string id)
@ -1801,11 +1789,7 @@ namespace Emby.Server.Implementations.LiveTv
.Select(i => i.Item1)
.ToArray();
return new QueryResult<SeriesTimerInfo>
{
Items = returnArray,
TotalRecordCount = returnArray.Length
};
return new QueryResult<SeriesTimerInfo>(returnArray);
}
public async Task<QueryResult<SeriesTimerInfoDto>> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken)
@ -1855,11 +1839,7 @@ namespace Emby.Server.Implementations.LiveTv
})
.ToArray();
return new QueryResult<SeriesTimerInfoDto>
{
Items = returnArray,
TotalRecordCount = returnArray.Length
};
return new QueryResult<SeriesTimerInfoDto>(returnArray);
}
public BaseItem GetLiveTvChannel(TimerInfo timer, ILiveTvService service)

View File

@ -304,11 +304,10 @@ namespace Emby.Server.Implementations.TV
items = items.Take(query.Limit.Value);
}
return new QueryResult<BaseItem>
{
TotalRecordCount = totalCount,
Items = items.ToArray()
};
return new QueryResult<BaseItem>(
query.StartIndex,
totalCount,
items.ToArray());
}
}
}

View File

@ -38,11 +38,7 @@ namespace Jellyfin.Api.Controllers
{
var keys = await _authenticationManager.GetApiKeys();
return new QueryResult<AuthenticationInfo>
{
Items = keys,
TotalRecordCount = keys.Count
};
return new QueryResult<AuthenticationInfo>(keys);
}
/// <summary>

View File

@ -243,11 +243,10 @@ namespace Jellyfin.Api.Controllers
return dto;
});
return new QueryResult<BaseItemDto>
{
Items = dtos.ToArray(),
TotalRecordCount = result.TotalRecordCount
};
return new QueryResult<BaseItemDto>(
query.StartIndex,
result.TotalRecordCount,
dtos.ToArray());
}
/// <summary>
@ -447,11 +446,10 @@ namespace Jellyfin.Api.Controllers
return dto;
});
return new QueryResult<BaseItemDto>
{
Items = dtos.ToArray(),
TotalRecordCount = result.TotalRecordCount
};
return new QueryResult<BaseItemDto>(
query.StartIndex,
result.TotalRecordCount,
dtos.ToArray());
}
/// <summary>

View File

@ -341,10 +341,7 @@ namespace Jellyfin.Api.Controllers
{
var list = items;
var result = new QueryResult<BaseItemDto>
{
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<BaseItemDto>(
0,
totalCount,
returnList);
return result;
}

View File

@ -491,10 +491,13 @@ namespace Jellyfin.Api.Controllers
else
{
var itemsArray = folder.GetChildren(user, true);
result = new QueryResult<BaseItem> { Items = itemsArray, TotalRecordCount = itemsArray.Count, StartIndex = 0 };
result = new QueryResult<BaseItem>(itemsArray);
}
return new QueryResult<BaseItemDto> { StartIndex = startIndex.GetValueOrDefault(), TotalRecordCount = result.TotalRecordCount, Items = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user) };
return new QueryResult<BaseItemDto>(
startIndex,
result.TotalRecordCount,
_dtoService.GetBaseItemDtos(result.Items, dtoOptions, user));
}
/// <summary>
@ -836,12 +839,10 @@ namespace Jellyfin.Api.Controllers
var returnItems = _dtoService.GetBaseItemDtos(itemsResult.Items, dtoOptions, user);
return new QueryResult<BaseItemDto>
{
StartIndex = startIndex.GetValueOrDefault(),
TotalRecordCount = itemsResult.TotalRecordCount,
Items = returnItems
};
return new QueryResult<BaseItemDto>(
startIndex,
itemsResult.TotalRecordCount,
returnItems);
}
}
}

View File

@ -506,13 +506,8 @@ namespace Jellyfin.Api.Controllers
}
var dtoOptions = new DtoOptions().AddClientFields(Request);
var result = new QueryResult<BaseItemDto>
{
TotalRecordCount = items.Count,
Items = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions)).ToArray()
};
return result;
var resultArray = _dtoService.GetBaseItemDtos(items, dtoOptions);
return new QueryResult<BaseItemDto>(resultArray);
}
/// <summary>
@ -759,11 +754,10 @@ namespace Jellyfin.Api.Controllers
var returnList = _dtoService.GetBaseItemDtos(itemsResult, dtoOptions, user);
return new QueryResult<BaseItemDto>
{
Items = returnList,
TotalRecordCount = itemsResult.Count
};
return new QueryResult<BaseItemDto>(
query.StartIndex,
itemsResult.Count,
returnList);
}
/// <summary>

View File

@ -193,11 +193,10 @@ namespace Jellyfin.Api.Controllers
dtoOptions.AddCurrentProgram = addCurrentProgram;
var returnArray = _dtoService.GetBaseItemDtos(channelResult.Items, dtoOptions, user);
return new QueryResult<BaseItemDto>
{
Items = returnArray,
TotalRecordCount = channelResult.TotalRecordCount
};
return new QueryResult<BaseItemDto>(
startIndex,
channelResult.TotalRecordCount,
returnArray);
}
/// <summary>
@ -390,11 +389,7 @@ namespace Jellyfin.Api.Controllers
var returnArray = _dtoService.GetBaseItemDtos(folders, new DtoOptions(), user);
return new QueryResult<BaseItemDto>
{
Items = returnArray,
TotalRecordCount = returnArray.Count
};
return new QueryResult<BaseItemDto>(returnArray);
}
/// <summary>

View File

@ -101,11 +101,7 @@ namespace Jellyfin.Api.Controllers
Limit = limit ?? 0
});
return new QueryResult<BaseItemDto>
{
Items = peopleItems.Select(person => _dtoService.GetItemByNameDto(person, dtoOptions, null, user)).ToArray(),
TotalRecordCount = peopleItems.Count
};
return new QueryResult<BaseItemDto>(peopleItems.Select(person => _dtoService.GetItemByNameDto(person, dtoOptions, null, user)).ToArray());
}
/// <summary>

View File

@ -208,11 +208,10 @@ namespace Jellyfin.Api.Controllers
dtos[index].PlaylistItemId = items[index].Item1.Id;
}
var result = new QueryResult<BaseItemDto>
{
Items = dtos,
TotalRecordCount = count
};
var result = new QueryResult<BaseItemDto>(
startIndex,
count,
dtos);
return result;
}

View File

@ -81,11 +81,10 @@ namespace Jellyfin.Api.Controllers
var dtoList = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user);
return new QueryResult<BaseItemDto>
{
TotalRecordCount = result.TotalRecordCount,
Items = dtoList
};
return new QueryResult<BaseItemDto>(
startIndex,
result.TotalRecordCount,
dtoList);
}
}
}

View File

@ -110,11 +110,10 @@ namespace Jellyfin.Api.Controllers
var returnItems = _dtoService.GetBaseItemDtos(result.Items, options, user);
return new QueryResult<BaseItemDto>
{
TotalRecordCount = result.TotalRecordCount,
Items = returnItems
};
return new QueryResult<BaseItemDto>(
startIndex,
result.TotalRecordCount,
returnItems);
}
/// <summary>
@ -169,11 +168,10 @@ namespace Jellyfin.Api.Controllers
var returnItems = _dtoService.GetBaseItemDtos(itemsResult, options, user);
return new QueryResult<BaseItemDto>
{
TotalRecordCount = itemsResult.Count,
Items = returnItems
};
return new QueryResult<BaseItemDto>(
startIndex,
itemsResult.Count,
returnItems);
}
/// <summary>
@ -296,11 +294,10 @@ namespace Jellyfin.Api.Controllers
var dtos = _dtoService.GetBaseItemDtos(returnItems, dtoOptions, user);
return new QueryResult<BaseItemDto>
{
TotalRecordCount = episodes.Count,
Items = dtos
};
return new QueryResult<BaseItemDto>(
startIndex,
episodes.Count,
dtos);
}
/// <summary>
@ -354,11 +351,7 @@ namespace Jellyfin.Api.Controllers
var returnItems = _dtoService.GetBaseItemDtos(seasons, dtoOptions, user);
return new QueryResult<BaseItemDto>
{
TotalRecordCount = returnItems.Count,
Items = returnItems
};
return new QueryResult<BaseItemDto>(returnItems);
}
/// <summary>

View File

@ -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<BaseItemDto>
{
Items = dtos,
TotalRecordCount = dtos.Length
};
return new QueryResult<BaseItemDto>(dtos);
}
/// <summary>

View File

@ -108,11 +108,7 @@ namespace Jellyfin.Api.Controllers
var dtos = folders.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user))
.ToArray();
return new QueryResult<BaseItemDto>
{
Items = dtos,
TotalRecordCount = dtos.Length
};
return new QueryResult<BaseItemDto>(dtos);
}
/// <summary>

View File

@ -134,12 +134,7 @@ namespace Jellyfin.Api.Controllers
items = Array.Empty<BaseItemDto>();
}
var result = new QueryResult<BaseItemDto>
{
Items = items,
TotalRecordCount = items.Length
};
var result = new QueryResult<BaseItemDto>(items);
return result;
}

View File

@ -136,8 +136,6 @@ namespace Jellyfin.Api.Controllers
IEnumerable<BaseItem> ibnItems = ibnItemsArray;
var result = new QueryResult<BaseItemDto> { 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<BaseItemDto>(
startIndex,
ibnItemsArray.Count,
dtos.Where(i => i != null).ToArray());
return result;
}

View File

@ -131,11 +131,10 @@ namespace Jellyfin.Api.Helpers
return dto;
});
return new QueryResult<BaseItemDto>
{
Items = dtos.ToArray(),
TotalRecordCount = result.TotalRecordCount
};
return new QueryResult<BaseItemDto>(
result.StartIndex,
result.TotalRecordCount,
dtos.ToArray());
}
}
}

View File

@ -59,17 +59,16 @@ namespace Jellyfin.Server.Implementations.Activity
entries = entries.Where(entry => entry.UserId != Guid.Empty == query.HasUserId.Value );
}
return new QueryResult<ActivityLogEntry>
{
Items = await entries
return new QueryResult<ActivityLogEntry>(
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));
}
/// <inheritdoc />

View File

@ -145,12 +145,10 @@ namespace Jellyfin.Server.Implementations.Devices
devices = devices.Take(query.Limit.Value);
}
return new QueryResult<Device>
{
Items = await devices.ToListAsync().ConfigureAwait(false),
StartIndex = query.Skip ?? 0,
TotalRecordCount = count
};
return new QueryResult<Device>(
query.Skip,
count,
await devices.ToListAsync().ConfigureAwait(false));
}
/// <inheritdoc />
@ -158,12 +156,10 @@ namespace Jellyfin.Server.Implementations.Devices
{
var devices = await GetDevices(query).ConfigureAwait(false);
return new QueryResult<DeviceInfo>
{
Items = devices.Items.Select(device => ToDeviceInfo(device)).ToList(),
StartIndex = devices.StartIndex,
TotalRecordCount = devices.TotalRecordCount
};
return new QueryResult<DeviceInfo>(
devices.StartIndex,
devices.TotalRecordCount,
devices.Items.Select(device => ToDeviceInfo(device)).ToList());
}
/// <inheritdoc />

View File

@ -783,11 +783,10 @@ namespace MediaBrowser.Controller.Entities
returnItems = returnItems.Skip(startIndex.Value);
}
return new QueryResult<BaseItem>
{
TotalRecordCount = totalCount,
Items = returnItems.ToArray()
};
return new QueryResult<BaseItem>(
query.StartIndex,
totalCount,
returnItems.ToArray());
}
private bool RequiresPostFiltering2(InternalItemsQuery query)

View File

@ -238,12 +238,7 @@ namespace MediaBrowser.Controller.Entities
private QueryResult<BaseItem> ConvertToResult(List<BaseItem> items)
{
var arr = items.ToArray();
return new QueryResult<BaseItem>
{
Items = arr,
TotalRecordCount = arr.Length
};
return new QueryResult<BaseItem>(items);
}
private QueryResult<BaseItem> GetMovieGenres(Folder parent, User user, InternalItemsQuery query)
@ -414,16 +409,6 @@ namespace MediaBrowser.Controller.Entities
return _libraryManager.GetItemsResult(query);
}
private QueryResult<BaseItem> GetResult<T>(QueryResult<T> result)
where T : BaseItem
{
return new QueryResult<BaseItem>
{
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<BaseItem> GetResult<T>(
IEnumerable<T> items,
InternalItemsQuery query)
@ -483,11 +468,10 @@ namespace MediaBrowser.Controller.Entities
itemsArray = itemsArray.Skip(query.StartIndex.Value).ToArray();
}
return new QueryResult<BaseItem>
{
TotalRecordCount = totalCount,
Items = itemsArray
};
return new QueryResult<BaseItem>(
query.StartIndex,
totalCount,
itemsArray);
}
public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager)

View File

@ -19,6 +19,13 @@ namespace MediaBrowser.Model.Querying
TotalRecordCount = items.Count;
}
public QueryResult(int? startIndex, int? totalRecordCount, IReadOnlyList<T> items)
{
StartIndex = startIndex ?? 0;
TotalRecordCount = totalRecordCount ?? items.Count;
Items = items;
}
/// <summary>
/// Gets or sets the items.
/// </summary>