From d28ee96f06f57483c24f5cfcb14152c6b79a9c7d Mon Sep 17 00:00:00 2001 From: Lampan-git <22211983+Lampan-git@users.noreply.github.com> Date: Tue, 25 Feb 2025 17:35:28 +0100 Subject: [PATCH 1/5] Include PeopleBaseItemMap in GetPeople --- .../Item/PeopleRepository.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs index a8dfd4cd3a..77b00a41a0 100644 --- a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs +++ b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs @@ -39,6 +39,30 @@ public class PeopleRepository(IDbContextFactory dbProvider, I dbQuery = dbQuery.Take(filter.Limit); } + // Include PeopleBaseItemMap + if (!filter.ItemId.IsEmpty()) + { + var people = dbQuery.ToArray(); + var peopleIds = people.Select(p => p.Id).ToArray(); + + var mappings = context.PeopleBaseItemMap + .AsNoTracking() + .Where(m => peopleIds.Contains(m.PeopleId) && m.ItemId == filter.ItemId) + .ToDictionary(m => m.PeopleId); + + return people.Select(p => + { + var personInfo = Map(p); + if (mappings.TryGetValue(p.Id, out var mapping)) + { + personInfo.Role = mapping.Role; + personInfo.SortOrder = mapping.SortOrder; + } + + return personInfo; + }).ToArray(); + } + return dbQuery.AsEnumerable().Select(Map).ToArray(); } From 4e3d7383f5cb85eb408f9d026b6da1986925df17 Mon Sep 17 00:00:00 2001 From: Lampan-git <22211983+Lampan-git@users.noreply.github.com> Date: Wed, 5 Mar 2025 16:59:31 +0100 Subject: [PATCH 2/5] Change GetPeople PeopleBaseItemMap code to query --- .../Item/PeopleRepository.cs | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs index 77b00a41a0..cca25de731 100644 --- a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs +++ b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs @@ -42,25 +42,23 @@ public class PeopleRepository(IDbContextFactory dbProvider, I // Include PeopleBaseItemMap if (!filter.ItemId.IsEmpty()) { - var people = dbQuery.ToArray(); - var peopleIds = people.Select(p => p.Id).ToArray(); + var query = dbQuery + .GroupJoin( + context.PeopleBaseItemMap.AsNoTracking().Where(m => m.ItemId == filter.ItemId), + person => person.Id, + mapping => mapping.PeopleId, + (person, mappings) => new { Person = person, Mapping = mappings.FirstOrDefault() }); - var mappings = context.PeopleBaseItemMap - .AsNoTracking() - .Where(m => peopleIds.Contains(m.PeopleId) && m.ItemId == filter.ItemId) - .ToDictionary(m => m.PeopleId); - - return people.Select(p => - { - var personInfo = Map(p); - if (mappings.TryGetValue(p.Id, out var mapping)) + return query + .AsEnumerable() + .Select(p => { - personInfo.Role = mapping.Role; - personInfo.SortOrder = mapping.SortOrder; - } - - return personInfo; - }).ToArray(); + var personInfo = Map(p.Person); + personInfo.Role = p.Mapping?.Role; + personInfo.SortOrder = p.Mapping?.SortOrder; + return personInfo; + }) + .ToArray(); } return dbQuery.AsEnumerable().Select(Map).ToArray(); From e137a063623daa421c34fc7d27ac2502d66b8e0b Mon Sep 17 00:00:00 2001 From: Lampan-git <22211983+Lampan-git@users.noreply.github.com> Date: Wed, 5 Mar 2025 16:58:34 +0100 Subject: [PATCH 3/5] Change PeopleBaseItemMap query from GroupJoin to Include --- .../Item/PeopleRepository.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs index cca25de731..28909cea78 100644 --- a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs +++ b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs @@ -42,20 +42,16 @@ public class PeopleRepository(IDbContextFactory dbProvider, I // Include PeopleBaseItemMap if (!filter.ItemId.IsEmpty()) { - var query = dbQuery - .GroupJoin( - context.PeopleBaseItemMap.AsNoTracking().Where(m => m.ItemId == filter.ItemId), - person => person.Id, - mapping => mapping.PeopleId, - (person, mappings) => new { Person = person, Mapping = mappings.FirstOrDefault() }); + dbQuery = dbQuery.Include(p => p.BaseItems!.Where(m => m.ItemId == filter.ItemId)); - return query + return dbQuery .AsEnumerable() .Select(p => { - var personInfo = Map(p.Person); - personInfo.Role = p.Mapping?.Role; - personInfo.SortOrder = p.Mapping?.SortOrder; + var personInfo = Map(p); + var mapping = p.BaseItems?.FirstOrDefault(); + personInfo.Role = mapping?.Role; + personInfo.SortOrder = mapping?.SortOrder; return personInfo; }) .ToArray(); From 7abb94d8a20072d451d6f58a0daa427efb5a93bf Mon Sep 17 00:00:00 2001 From: Lampan-git <22211983+Lampan-git@users.noreply.github.com> Date: Wed, 5 Mar 2025 22:37:18 +0100 Subject: [PATCH 4/5] Move mapping assignment to Map --- .../Item/PeopleRepository.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs index 28909cea78..1396f1c6f8 100644 --- a/Jellyfin.Server.Implementations/Item/PeopleRepository.cs +++ b/Jellyfin.Server.Implementations/Item/PeopleRepository.cs @@ -43,18 +43,6 @@ public class PeopleRepository(IDbContextFactory dbProvider, I if (!filter.ItemId.IsEmpty()) { dbQuery = dbQuery.Include(p => p.BaseItems!.Where(m => m.ItemId == filter.ItemId)); - - return dbQuery - .AsEnumerable() - .Select(p => - { - var personInfo = Map(p); - var mapping = p.BaseItems?.FirstOrDefault(); - personInfo.Role = mapping?.Role; - personInfo.SortOrder = mapping?.SortOrder; - return personInfo; - }) - .ToArray(); } return dbQuery.AsEnumerable().Select(Map).ToArray(); @@ -111,10 +99,13 @@ public class PeopleRepository(IDbContextFactory dbProvider, I private PersonInfo Map(People people) { + var mapping = people.BaseItems?.FirstOrDefault(); var personInfo = new PersonInfo() { Id = people.Id, Name = people.Name, + Role = mapping?.Role, + SortOrder = mapping?.SortOrder }; if (Enum.TryParse(people.PersonType, out var kind)) { From cf1f251f2a2115c84539f41603252a6733e02482 Mon Sep 17 00:00:00 2001 From: Lampan-git <22211983+Lampan-git@users.noreply.github.com> Date: Fri, 14 Mar 2025 21:07:34 +0100 Subject: [PATCH 5/5] Preserve null sortOrder during migration --- Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs index 3289484f93..f826131fc4 100644 --- a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs +++ b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs @@ -240,9 +240,7 @@ public class MigrateLibraryDb : IMigrationRoutine { } - if (reader.TryGetInt32(4, out var sortOrder)) - { - } + int? sortOrder = reader.IsDBNull(4) ? null : reader.GetInt32(4); personCache.Items.Add(new PeopleBaseItemMap() {