mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-05 00:06:35 +01:00
Merge pull request #16616 from dkanada/fix-person-limit
fix person TotalRecordCount when limit is applied
This commit is contained in:
@@ -3253,7 +3253,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
public IReadOnlyList<PersonInfo> GetPeople(InternalPeopleQuery query)
|
||||
{
|
||||
return _peopleRepository.GetPeople(query);
|
||||
return _peopleRepository.GetPeople(query).Items;
|
||||
}
|
||||
|
||||
public IReadOnlyList<PersonInfo> GetPeople(BaseItem item)
|
||||
@@ -3274,24 +3274,33 @@ namespace Emby.Server.Implementations.Library
|
||||
return [];
|
||||
}
|
||||
|
||||
public IReadOnlyList<Person> GetPeopleItems(InternalPeopleQuery query)
|
||||
public QueryResult<BaseItem> GetPeopleItems(InternalPeopleQuery query)
|
||||
{
|
||||
return _peopleRepository.GetPeopleNames(query)
|
||||
.Select(i =>
|
||||
var queryResult = _peopleRepository.GetPeople(query);
|
||||
var baseItems = queryResult.Items.Select(i =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetPerson(i.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "error retrieving BaseItem for person: {0}", i.Name);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.Where(i => i is not null)
|
||||
.Where(i => query.User is null || i!.IsVisible(query.User))
|
||||
.OfType<BaseItem>()
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
|
||||
return new QueryResult<BaseItem>
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetPerson(i);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error getting person");
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.Where(i => i is not null)
|
||||
.Where(i => query.User is null || i!.IsVisible(query.User))
|
||||
.ToList()!; // null values are filtered out
|
||||
StartIndex = queryResult.StartIndex,
|
||||
TotalRecordCount = queryResult.TotalRecordCount,
|
||||
Items = baseItems,
|
||||
};
|
||||
}
|
||||
|
||||
public IReadOnlyList<string> GetPeopleNames(InternalPeopleQuery query)
|
||||
|
||||
@@ -116,9 +116,11 @@ public class PersonsController : BaseJellyfinApiController
|
||||
});
|
||||
|
||||
return new QueryResult<BaseItemDto>(
|
||||
peopleItems
|
||||
.Select(person => _dtoService.GetItemByNameDto(person, dtoOptions, null, user))
|
||||
.ToArray());
|
||||
peopleItems.StartIndex,
|
||||
peopleItems.TotalRecordCount,
|
||||
peopleItems.Items
|
||||
.Select(person => _dtoService.GetItemByNameDto(person, dtoOptions, null, user))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Jellyfin.Data.Enums;
|
||||
using Jellyfin.Database.Implementations;
|
||||
using Jellyfin.Database.Implementations.Entities;
|
||||
using Jellyfin.Database.Implementations.Entities.Libraries;
|
||||
using Jellyfin.Extensions;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Item;
|
||||
@@ -30,7 +29,7 @@ public class PeopleRepository(IDbContextFactory<JellyfinDbContext> dbProvider, I
|
||||
private readonly IDbContextFactory<JellyfinDbContext> _dbProvider = dbProvider;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IReadOnlyList<PersonInfo> GetPeople(InternalPeopleQuery filter)
|
||||
public QueryResult<PersonInfo> GetPeople(InternalPeopleQuery filter)
|
||||
{
|
||||
using var context = _dbProvider.CreateDbContext();
|
||||
var dbQuery = TranslateQuery(context.Peoples.AsNoTracking(), context, filter);
|
||||
@@ -48,12 +47,23 @@ public class PeopleRepository(IDbContextFactory<JellyfinDbContext> dbProvider, I
|
||||
dbQuery = dbQuery.OrderBy(e => e.Name);
|
||||
}
|
||||
|
||||
var count = dbQuery.Count();
|
||||
if (filter.StartIndex.HasValue && filter.StartIndex > 0)
|
||||
{
|
||||
dbQuery = dbQuery.Skip(filter.StartIndex.Value);
|
||||
}
|
||||
|
||||
if (filter.Limit > 0)
|
||||
{
|
||||
dbQuery = dbQuery.Take(filter.Limit);
|
||||
}
|
||||
|
||||
return dbQuery.AsEnumerable().Select(Map).ToArray();
|
||||
return new QueryResult<PersonInfo>
|
||||
{
|
||||
StartIndex = filter.StartIndex ?? 0,
|
||||
TotalRecordCount = count,
|
||||
Items = dbQuery.AsEnumerable().Select(Map).ToArray(),
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -558,7 +558,7 @@ namespace MediaBrowser.Controller.Library
|
||||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>List<Person>.</returns>
|
||||
IReadOnlyList<Person> GetPeopleItems(InternalPeopleQuery query);
|
||||
QueryResult<BaseItem> GetPeopleItems(InternalPeopleQuery query);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the people.
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Querying;
|
||||
|
||||
namespace MediaBrowser.Controller.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// Provides methods for accessing Peoples.
|
||||
/// </summary>
|
||||
public interface IPeopleRepository
|
||||
{
|
||||
/// <summary>
|
||||
@@ -15,7 +17,7 @@ public interface IPeopleRepository
|
||||
/// </summary>
|
||||
/// <param name="filter">The query.</param>
|
||||
/// <returns>The list of people matching the filter.</returns>
|
||||
IReadOnlyList<PersonInfo> GetPeople(InternalPeopleQuery filter);
|
||||
QueryResult<PersonInfo> GetPeople(InternalPeopleQuery filter);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the people.
|
||||
|
||||
Reference in New Issue
Block a user