Merge pull request #17571 from obiwantoby/perf/batch-people-dto

Batch people lookups when building item DTOs
This commit is contained in:
Cody Robibero
2026-08-07 21:43:21 -04:00
committed by GitHub
6 changed files with 149 additions and 5 deletions
@@ -236,6 +236,53 @@ public class PeopleRepository(IDbContextFactory<JellyfinDbContext> dbProvider, I
return result;
}
/// <inheritdoc/>
public IReadOnlyDictionary<Guid, IReadOnlyList<PersonInfo>> GetPeopleByItems(IReadOnlyList<Guid> itemIds)
{
using var context = _dbProvider.CreateDbContext();
var rows = context.PeopleBaseItemMap
.AsNoTracking()
.Where(m => itemIds.Contains(m.ItemId))
.OrderBy(m => m.ListOrder)
.Select(m => new
{
m.ItemId,
m.Role,
m.SortOrder,
m.People.Id,
m.People.Name,
m.People.PersonType
})
.ToList();
var result = new Dictionary<Guid, IReadOnlyList<PersonInfo>>();
foreach (var group in rows.GroupBy(r => r.ItemId))
{
var people = new List<PersonInfo>();
foreach (var row in group)
{
var personInfo = new PersonInfo
{
ItemId = row.ItemId,
Id = row.Id,
Name = row.Name,
Role = row.Role,
SortOrder = row.SortOrder
};
if (Enum.TryParse<PersonKind>(row.PersonType, out var kind))
{
personInfo.Type = kind;
}
people.Add(personInfo);
}
result[group.Key] = people;
}
return result;
}
private IEnumerable<PersonInfo> MapCredits(People people)
{
var mappings = people.BaseItems;