aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations
diff options
context:
space:
mode:
authorevan314159 <110177090+evan314159@users.noreply.github.com>2025-12-09 12:15:46 +0800
committerGitHub <noreply@github.com>2025-12-08 21:15:46 -0700
commit8b2a8b94b6361e31eff58078225cf78d8a6c3fb1 (patch)
treef19d6c4cac15b2f23f216fda2bf79c4218ed4edc /Jellyfin.Server.Implementations
parentf24e80701cca2398b9efea8605bd406ff36f3746 (diff)
avoid Take(0) when limit == 0 (#14608)
Co-authored-by: Evan <evan@MacBook-Pro.local>
Diffstat (limited to 'Jellyfin.Server.Implementations')
-rw-r--r--Jellyfin.Server.Implementations/Devices/DeviceManager.cs2
-rw-r--r--Jellyfin.Server.Implementations/Item/BaseItemRepository.cs44
2 files changed, 18 insertions, 28 deletions
diff --git a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs
index 51a118645..bcf348f8c 100644
--- a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs
+++ b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs
@@ -158,7 +158,7 @@ namespace Jellyfin.Server.Implementations.Devices
devices = devices.Skip(query.Skip.Value);
}
- if (query.Limit.HasValue)
+ if (query.Limit.HasValue && query.Limit.Value > 0)
{
devices = devices.Take(query.Limit.Value);
}
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
index 57d874e59..dfe46ef8f 100644
--- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
+++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
@@ -250,7 +250,7 @@ public sealed class BaseItemRepository
public QueryResult<BaseItemDto> GetItems(InternalItemsQuery 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);
return new QueryResult<BaseItemDto>(
@@ -326,7 +326,7 @@ public sealed class BaseItemRepository
.OrderByDescending(g => g.MaxDateCreated)
.Select(g => g);
- if (filter.Limit.HasValue)
+ if (filter.Limit.HasValue && filter.Limit.Value > 0)
{
subqueryGrouped = subqueryGrouped.Take(filter.Limit.Value);
}
@@ -367,7 +367,7 @@ public sealed class BaseItemRepository
.OrderByDescending(g => g.LastPlayedDate)
.Select(g => g.Key!);
- if (filter.Limit.HasValue)
+ if (filter.Limit.HasValue && filter.Limit.Value > 0)
{
query = query.Take(filter.Limit.Value);
}
@@ -425,19 +425,14 @@ public sealed class BaseItemRepository
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;
-
- if (offset > 0)
- {
- dbQuery = dbQuery.Skip(offset);
- }
+ dbQuery = dbQuery.Skip(filter.StartIndex.Value);
+ }
- if (filter.Limit.HasValue)
- {
- dbQuery = dbQuery.Take(filter.Limit.Value);
- }
+ if (filter.Limit.HasValue && filter.Limit.Value > 0)
+ {
+ dbQuery = dbQuery.Take(filter.Limit.Value);
}
return dbQuery;
@@ -1190,7 +1185,7 @@ public sealed class BaseItemRepository
{
ArgumentNullException.ThrowIfNull(filter);
- if (!filter.Limit.HasValue)
+ if (!(filter.Limit.HasValue && filter.Limit.Value > 0))
{
filter.EnableTotalRecordCount = false;
}
@@ -1269,19 +1264,14 @@ public sealed class BaseItemRepository
result.TotalRecordCount = query.Count();
}
- if (filter.Limit.HasValue || filter.StartIndex.HasValue)
+ if (filter.StartIndex.HasValue && filter.StartIndex.Value > 0)
{
- var offset = filter.StartIndex ?? 0;
-
- if (offset > 0)
- {
- query = query.Skip(offset);
- }
+ query = query.Skip(filter.StartIndex.Value);
+ }
- if (filter.Limit.HasValue)
- {
- query = query.Take(filter.Limit.Value);
- }
+ if (filter.Limit.HasValue && filter.Limit.Value > 0)
+ {
+ query = query.Take(filter.Limit.Value);
}
IQueryable<BaseItemEntity>? itemCountQuery = null;
@@ -1362,7 +1352,7 @@ public sealed class BaseItemRepository
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;
}