aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2026-09-01 19:49:25 +0200
committerShadowghost <Ghost_of_Stone@web.de>2026-09-01 19:49:25 +0200
commit50f08d41a411254f67cf2305fd7bb838119a1bc1 (patch)
tree14c5433591dba61df45ab7c254757735c3b25256 /Emby.Server.Implementations/Library/Validators/PeopleValidator.cs
parent792ce4a391c524f8e20f676be2d6cab07e5a59c4 (diff)
Find dead people and artists by id, not by name
Diffstat (limited to 'Emby.Server.Implementations/Library/Validators/PeopleValidator.cs')
-rw-r--r--Emby.Server.Implementations/Library/Validators/PeopleValidator.cs56
1 files changed, 49 insertions, 7 deletions
diff --git a/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs
index 3c8806d549..7d53f40ce7 100644
--- a/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs
+++ b/Emby.Server.Implementations/Library/Validators/PeopleValidator.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
@@ -58,6 +59,8 @@ public class PeopleValidator
IncludeItemTypes = [BaseItemKind.Person]
}).ToHashSet();
+ var (newNames, deadIds) = PartitionCreditsByPersonId(names, _libraryManager.GetPersonId, existingPersonIds);
+
var numComplete = 0;
var count = names.Count;
var refreshed = 0;
@@ -96,14 +99,18 @@ public class PeopleValidator
progress.Report(percent);
}
- _logger.LogInformation("Refreshed metadata for {RefreshedCount} new people out of {TotalCount} total", refreshed, count);
+ _logger.LogInformation(
+ "Refreshed metadata for {RefreshedCount} people out of {TotalCount} total, {NewCount} of which had no item yet",
+ refreshed,
+ count,
+ newNames.Count);
- var deadEntities = _libraryManager.GetItemList(new InternalItemsQuery
- {
- IncludeItemTypes = [BaseItemKind.Person],
- IsDeadPerson = true,
- IsLocked = false
- });
+ // A person somebody locked is theirs, not ours, however little the library still credits them.
+ var deadEntities = deadIds
+ .Select(_libraryManager.GetItemById)
+ .OfType<Person>()
+ .Where(item => !item.IsLocked)
+ .ToList();
foreach (var item in deadEntities)
{
@@ -114,4 +121,39 @@ public class PeopleValidator
progress.Report(100);
}
+
+ /// <summary>
+ /// Splits the person items into the ones a credit still calls for and the ones nothing does.
+ /// </summary>
+ /// <param name="creditNames">Every name credited on an item, from the people table.</param>
+ /// <param name="getPersonId">Maps a credit name to the id its person item has.</param>
+ /// <param name="existingPersonIds">The ids of the person items that exist.</param>
+ /// <returns>The credits needing an item, and the ids of the items nothing credits.</returns>
+ internal static (List<string> NewNames, List<Guid> DeadIds) PartitionCreditsByPersonId(
+ IReadOnlyList<string> creditNames,
+ Func<string, Guid> getPersonId,
+ IReadOnlySet<Guid> existingPersonIds)
+ {
+ ArgumentNullException.ThrowIfNull(creditNames);
+ ArgumentNullException.ThrowIfNull(getPersonId);
+ ArgumentNullException.ThrowIfNull(existingPersonIds);
+
+ var newNames = new List<string>();
+ var liveIds = new HashSet<Guid>();
+
+ foreach (var name in creditNames)
+ {
+ var personId = getPersonId(name);
+
+ // Distinct credit names can normalize onto one id; only the first of them needs an item.
+ if (liveIds.Add(personId) && !existingPersonIds.Contains(personId))
+ {
+ newNames.Add(name);
+ }
+ }
+
+ var deadIds = existingPersonIds.Where(id => !liveIds.Contains(id)).ToList();
+
+ return (newNames, deadIds);
+ }
}