Fix people deduplication lookup (#14864)

This commit is contained in:
JPVenson 2025-09-26 04:27:38 +03:00 committed by GitHub
parent 1736a566cc
commit 54d48fa446
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1786 additions and 6 deletions

View File

@ -74,6 +74,11 @@ public class PeopleRepository(IDbContextFactory<JellyfinDbContext> dbProvider, I
/// <inheritdoc />
public void UpdatePeople(Guid itemId, IReadOnlyList<PersonInfo> people)
{
foreach (var item in people.Where(e => e.Role is null))
{
item.Role = string.Empty;
}
// multiple metadata providers can provide the _same_ person
people = people.DistinctBy(e => e.Name + "-" + e.Type).ToArray();
var personKeys = people.Select(e => e.Name + "-" + e.Type).ToArray();
@ -106,7 +111,7 @@ public class PeopleRepository(IDbContextFactory<JellyfinDbContext> dbProvider, I
foreach (var person in people)
{
var entityPerson = personsEntities.First(e => e.Name == person.Name && e.PersonType == person.Type.ToString());
var existingMap = existingMaps.FirstOrDefault(e => e.People.Name == person.Name && e.Role == person.Role);
var existingMap = existingMaps.FirstOrDefault(e => e.People.Name == person.Name && e.People.PersonType == person.Type.ToString() && e.Role == person.Role);
if (existingMap is null)
{
var sortOrder = person.Type == PersonKind.Actor ? (person.SortOrder ?? ++maxSortOrder) : person.SortOrder;

View File

@ -12,7 +12,7 @@ public class PeopleBaseItemMapConfiguration : IEntityTypeConfiguration<PeopleBas
/// <inheritdoc/>
public void Configure(EntityTypeBuilder<PeopleBaseItemMap> builder)
{
builder.HasKey(e => new { e.ItemId, e.PeopleId });
builder.HasKey(e => new { e.ItemId, e.PeopleId, e.Role });
builder.HasIndex(e => new { e.ItemId, e.SortOrder });
builder.HasIndex(e => new { e.ItemId, e.ListOrder });
builder.HasOne(e => e.Item);

View File

@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Jellyfin.Server.Implementations.Migrations
{
/// <inheritdoc />
public partial class ExtendPeopleMapKey : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_PeopleBaseItemMap",
table: "PeopleBaseItemMap");
migrationBuilder.AlterColumn<string>(
name: "Role",
table: "PeopleBaseItemMap",
type: "TEXT",
nullable: false,
defaultValue: string.Empty,
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
migrationBuilder.AddPrimaryKey(
name: "PK_PeopleBaseItemMap",
table: "PeopleBaseItemMap",
columns: new[] { "ItemId", "PeopleId", "Role" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_PeopleBaseItemMap",
table: "PeopleBaseItemMap");
migrationBuilder.AlterColumn<string>(
name: "Role",
table: "PeopleBaseItemMap",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT");
migrationBuilder.AddPrimaryKey(
name: "PK_PeopleBaseItemMap",
table: "PeopleBaseItemMap",
columns: new[] { "ItemId", "PeopleId" });
}
}
}

View File

@ -999,16 +999,16 @@ namespace Jellyfin.Server.Implementations.Migrations
b.Property<Guid>("PeopleId")
.HasColumnType("TEXT");
b.Property<int?>("ListOrder")
.HasColumnType("INTEGER");
b.Property<string>("Role")
.HasColumnType("TEXT");
b.Property<int?>("ListOrder")
.HasColumnType("INTEGER");
b.Property<int?>("SortOrder")
.HasColumnType("INTEGER");
b.HasKey("ItemId", "PeopleId");
b.HasKey("ItemId", "PeopleId", "Role");
b.HasIndex("PeopleId");