mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-15 08:23:28 -03:00
avoid Take(0) when limit == 0 (#14608)
Co-authored-by: Evan <evan@MacBook-Pro.local>
This commit is contained in:
@@ -42,7 +42,7 @@ namespace Emby.Server.Implementations.Library
|
|||||||
results = results.GetRange(query.StartIndex.Value, totalRecordCount - query.StartIndex.Value);
|
results = results.GetRange(query.StartIndex.Value, totalRecordCount - query.StartIndex.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.Limit.HasValue)
|
if (query.Limit.HasValue && query.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
results = results.GetRange(0, Math.Min(query.Limit.Value, results.Count));
|
results = results.GetRange(0, Math.Min(query.Limit.Value, results.Count));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ namespace Emby.Server.Implementations.TV
|
|||||||
items = items.Skip(query.StartIndex.Value);
|
items = items.Skip(query.StartIndex.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.Limit.HasValue)
|
if (query.Limit.HasValue && query.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
items = items.Take(query.Limit.Value);
|
items = items.Take(query.Limit.Value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ namespace Jellyfin.Server.Implementations.Devices
|
|||||||
devices = devices.Skip(query.Skip.Value);
|
devices = devices.Skip(query.Skip.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.Limit.HasValue)
|
if (query.Limit.HasValue && query.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
devices = devices.Take(query.Limit.Value);
|
devices = devices.Take(query.Limit.Value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ public sealed class BaseItemRepository
|
|||||||
public QueryResult<BaseItemDto> GetItems(InternalItemsQuery filter)
|
public QueryResult<BaseItemDto> GetItems(InternalItemsQuery filter)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(filter);
|
ArgumentNullException.ThrowIfNull(filter);
|
||||||
if (!filter.EnableTotalRecordCount || (!filter.Limit.HasValue && (filter.StartIndex ?? 0) == 0))
|
if (!filter.EnableTotalRecordCount || ((filter.Limit ?? 0) == 0 && (filter.StartIndex ?? 0) == 0))
|
||||||
{
|
{
|
||||||
var returnList = GetItemList(filter);
|
var returnList = GetItemList(filter);
|
||||||
return new QueryResult<BaseItemDto>(
|
return new QueryResult<BaseItemDto>(
|
||||||
@@ -326,7 +326,7 @@ public sealed class BaseItemRepository
|
|||||||
.OrderByDescending(g => g.MaxDateCreated)
|
.OrderByDescending(g => g.MaxDateCreated)
|
||||||
.Select(g => g);
|
.Select(g => g);
|
||||||
|
|
||||||
if (filter.Limit.HasValue)
|
if (filter.Limit.HasValue && filter.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
subqueryGrouped = subqueryGrouped.Take(filter.Limit.Value);
|
subqueryGrouped = subqueryGrouped.Take(filter.Limit.Value);
|
||||||
}
|
}
|
||||||
@@ -367,7 +367,7 @@ public sealed class BaseItemRepository
|
|||||||
.OrderByDescending(g => g.LastPlayedDate)
|
.OrderByDescending(g => g.LastPlayedDate)
|
||||||
.Select(g => g.Key!);
|
.Select(g => g.Key!);
|
||||||
|
|
||||||
if (filter.Limit.HasValue)
|
if (filter.Limit.HasValue && filter.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
query = query.Take(filter.Limit.Value);
|
query = query.Take(filter.Limit.Value);
|
||||||
}
|
}
|
||||||
@@ -425,19 +425,14 @@ public sealed class BaseItemRepository
|
|||||||
|
|
||||||
private IQueryable<BaseItemEntity> ApplyQueryPaging(IQueryable<BaseItemEntity> dbQuery, InternalItemsQuery filter)
|
private IQueryable<BaseItemEntity> ApplyQueryPaging(IQueryable<BaseItemEntity> dbQuery, InternalItemsQuery filter)
|
||||||
{
|
{
|
||||||
if (filter.Limit.HasValue || filter.StartIndex.HasValue)
|
if (filter.StartIndex.HasValue && filter.StartIndex.Value > 0)
|
||||||
{
|
{
|
||||||
var offset = filter.StartIndex ?? 0;
|
dbQuery = dbQuery.Skip(filter.StartIndex.Value);
|
||||||
|
}
|
||||||
|
|
||||||
if (offset > 0)
|
if (filter.Limit.HasValue && filter.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
dbQuery = dbQuery.Skip(offset);
|
dbQuery = dbQuery.Take(filter.Limit.Value);
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.Limit.HasValue)
|
|
||||||
{
|
|
||||||
dbQuery = dbQuery.Take(filter.Limit.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dbQuery;
|
return dbQuery;
|
||||||
@@ -1190,7 +1185,7 @@ public sealed class BaseItemRepository
|
|||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(filter);
|
ArgumentNullException.ThrowIfNull(filter);
|
||||||
|
|
||||||
if (!filter.Limit.HasValue)
|
if (!(filter.Limit.HasValue && filter.Limit.Value > 0))
|
||||||
{
|
{
|
||||||
filter.EnableTotalRecordCount = false;
|
filter.EnableTotalRecordCount = false;
|
||||||
}
|
}
|
||||||
@@ -1269,19 +1264,14 @@ public sealed class BaseItemRepository
|
|||||||
result.TotalRecordCount = query.Count();
|
result.TotalRecordCount = query.Count();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.Limit.HasValue || filter.StartIndex.HasValue)
|
if (filter.StartIndex.HasValue && filter.StartIndex.Value > 0)
|
||||||
{
|
{
|
||||||
var offset = filter.StartIndex ?? 0;
|
query = query.Skip(filter.StartIndex.Value);
|
||||||
|
}
|
||||||
|
|
||||||
if (offset > 0)
|
if (filter.Limit.HasValue && filter.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
query = query.Skip(offset);
|
query = query.Take(filter.Limit.Value);
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.Limit.HasValue)
|
|
||||||
{
|
|
||||||
query = query.Take(filter.Limit.Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IQueryable<BaseItemEntity>? itemCountQuery = null;
|
IQueryable<BaseItemEntity>? itemCountQuery = null;
|
||||||
@@ -1362,7 +1352,7 @@ public sealed class BaseItemRepository
|
|||||||
|
|
||||||
private static void PrepareFilterQuery(InternalItemsQuery query)
|
private static void PrepareFilterQuery(InternalItemsQuery query)
|
||||||
{
|
{
|
||||||
if (query.Limit.HasValue && query.EnableGroupByMetadataKey)
|
if (query.Limit.HasValue && query.Limit.Value > 0 && query.EnableGroupByMetadataKey)
|
||||||
{
|
{
|
||||||
query.Limit = query.Limit.Value + 4;
|
query.Limit = query.Limit.Value + 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ namespace MediaBrowser.Controller.Entities
|
|||||||
var itemsArray = totalRecordLimit.HasValue ? items.Take(totalRecordLimit.Value).ToArray() : items.ToArray();
|
var itemsArray = totalRecordLimit.HasValue ? items.Take(totalRecordLimit.Value).ToArray() : items.ToArray();
|
||||||
var totalCount = itemsArray.Length;
|
var totalCount = itemsArray.Length;
|
||||||
|
|
||||||
if (query.Limit.HasValue)
|
if (query.Limit.HasValue && query.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
itemsArray = itemsArray.Skip(query.StartIndex ?? 0).Take(query.Limit.Value).ToArray();
|
itemsArray = itemsArray.Skip(query.StartIndex ?? 0).Take(query.Limit.Value).ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,12 +240,9 @@ namespace Jellyfin.LiveTv.Channels
|
|||||||
var all = channels;
|
var all = channels;
|
||||||
var totalCount = all.Count;
|
var totalCount = all.Count;
|
||||||
|
|
||||||
if (query.StartIndex.HasValue || query.Limit.HasValue)
|
int startIndex = query.StartIndex ?? 0;
|
||||||
{
|
int count = (query.Limit ?? 0) > 0 ? Math.Min(query.Limit.Value, totalCount - startIndex) : totalCount - startIndex;
|
||||||
int startIndex = query.StartIndex ?? 0;
|
all = all.GetRange(query.StartIndex ?? 0, count);
|
||||||
int count = query.Limit is null ? totalCount - startIndex : Math.Min(query.Limit.Value, totalCount - startIndex);
|
|
||||||
all = all.GetRange(startIndex, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (query.RefreshLatestChannelItems)
|
if (query.RefreshLatestChannelItems)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ namespace Jellyfin.LiveTv
|
|||||||
GenreIds = query.GenreIds
|
GenreIds = query.GenreIds
|
||||||
};
|
};
|
||||||
|
|
||||||
if (query.Limit.HasValue)
|
if (query.Limit.HasValue && query.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
internalQuery.Limit = Math.Max(query.Limit.Value * 4, 200);
|
internalQuery.Limit = Math.Max(query.Limit.Value * 4, 200);
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,7 @@ namespace Jellyfin.LiveTv
|
|||||||
|
|
||||||
IEnumerable<BaseItem> programs = orderedPrograms;
|
IEnumerable<BaseItem> programs = orderedPrograms;
|
||||||
|
|
||||||
if (query.Limit.HasValue)
|
if (query.Limit.HasValue && query.Limit.Value > 0)
|
||||||
{
|
{
|
||||||
programs = programs.Take(query.Limit.Value);
|
programs = programs.Take(query.Limit.Value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user