aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Database/Jellyfin.Database.Implementations
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2026-01-17 15:06:10 +0100
committerShadowghost <Ghost_of_Stone@web.de>2026-01-18 19:46:37 +0100
commit139d23ddc29b6bafad5f8e6ba9eddc8484ab0713 (patch)
tree4d2d56f9d524c20c65ca9369dac530c9a1f70b43 /src/Jellyfin.Database/Jellyfin.Database.Implementations
parentcc2ccd1bf344ec38059164d1aa9b261e50807eac (diff)
Normalize OwnerId to GUID and add performance indexes
- Change OwnerId from string to Guid for proper foreign key relationships - Add Owner/Extras navigation properties for extras relationship - Add indexes on OwnerId and ExtraType columns for efficient queries - Add optimized composite indexes for latest items queries sorted by DateCreated - Update BaseItemRepository and migration to handle new Guid type
Diffstat (limited to 'src/Jellyfin.Database/Jellyfin.Database.Implementations')
-rw-r--r--src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/BaseItemEntity.cs12
-rw-r--r--src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/BaseItemConfiguration.cs10
2 files changed, 20 insertions, 2 deletions
diff --git a/src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/BaseItemEntity.cs b/src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/BaseItemEntity.cs
index 73e6e338ec..c51f331366 100644
--- a/src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/BaseItemEntity.cs
+++ b/src/Jellyfin.Database/Jellyfin.Database.Implementations/Entities/BaseItemEntity.cs
@@ -134,7 +134,17 @@ public class BaseItemEntity
public string? ShowId { get; set; }
- public string? OwnerId { get; set; }
+ public Guid? OwnerId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the owner item (for extras like trailers, theme songs, etc.).
+ /// </summary>
+ public BaseItemEntity? Owner { get; set; }
+
+ /// <summary>
+ /// Gets or sets the extras owned by this item (trailers, theme songs, behind the scenes, etc.).
+ /// </summary>
+ public ICollection<BaseItemEntity>? Extras { get; set; }
public int? Width { get; set; }
diff --git a/src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/BaseItemConfiguration.cs b/src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/BaseItemConfiguration.cs
index 6fccfd976d..4ec1b972dd 100644
--- a/src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/BaseItemConfiguration.cs
+++ b/src/Jellyfin.Database/Jellyfin.Database.Implementations/ModelConfiguration/BaseItemConfiguration.cs
@@ -28,12 +28,16 @@ public class BaseItemConfiguration : IEntityTypeConfiguration<BaseItemEntity>
builder.HasMany(e => e.Parents);
builder.HasMany(e => e.Children);
builder.HasMany(e => e.DirectChildren).WithOne(e => e.DirectParent).HasForeignKey(e => e.ParentId).OnDelete(DeleteBehavior.Cascade);
+ builder.HasMany(e => e.Extras).WithOne(e => e.Owner).HasForeignKey(e => e.OwnerId).OnDelete(DeleteBehavior.NoAction);
builder.HasMany(e => e.LockedFields);
builder.HasMany(e => e.TrailerTypes);
builder.HasMany(e => e.Images);
builder.HasIndex(e => e.Path);
builder.HasIndex(e => e.ParentId);
+ builder.HasIndex(e => e.OwnerId);
+ builder.HasIndex(e => e.ExtraType);
+ builder.HasIndex(e => new { e.ExtraType, e.OwnerId });
builder.HasIndex(e => e.PresentationUniqueKey);
builder.HasIndex(e => new { e.Id, e.Type, e.IsFolder, e.IsVirtualItem });
@@ -53,6 +57,10 @@ public class BaseItemConfiguration : IEntityTypeConfiguration<BaseItemEntity>
// latest items
builder.HasIndex(e => new { e.Type, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated });
builder.HasIndex(e => new { e.IsFolder, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated });
+ // latest items - optimized for sorting by DateCreated (no PresentationUniqueKey breaking the sort)
+ builder.HasIndex(e => new { e.TopParentId, e.Type, e.IsVirtualItem, e.DateCreated });
+ builder.HasIndex(e => new { e.TopParentId, e.IsFolder, e.IsVirtualItem, e.DateCreated });
+ builder.HasIndex(e => new { e.TopParentId, e.MediaType, e.IsVirtualItem, e.DateCreated });
// resume
builder.HasIndex(e => new { e.MediaType, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey });
@@ -60,7 +68,7 @@ public class BaseItemConfiguration : IEntityTypeConfiguration<BaseItemEntity>
{
Id = Guid.Parse("00000000-0000-0000-0000-000000000001"),
Type = "PLACEHOLDER",
- Name = "This is a placeholder item for UserData that has been detacted from its original item",
+ Name = "This is a placeholder item for UserData that has been detached from its original item",
});
}
}