| | 1 | | using Jellyfin.Database.Implementations.Entities; |
| | 2 | | using Microsoft.EntityFrameworkCore; |
| | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | 4 | |
|
| | 5 | | namespace Jellyfin.Database.Implementations.ModelConfiguration; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// Configuration for BaseItem. |
| | 9 | | /// </summary> |
| | 10 | | public class BaseItemConfiguration : IEntityTypeConfiguration<BaseItemEntity> |
| | 11 | | { |
| | 12 | | /// <inheritdoc/> |
| | 13 | | public void Configure(EntityTypeBuilder<BaseItemEntity> builder) |
| | 14 | | { |
| 2 | 15 | | builder.HasKey(e => e.Id); |
| | 16 | | // TODO: See rant in entity file. |
| | 17 | | // builder.HasOne(e => e.Parent).WithMany(e => e.DirectChildren).HasForeignKey(e => e.ParentId); |
| | 18 | | // builder.HasOne(e => e.TopParent).WithMany(e => e.AllChildren).HasForeignKey(e => e.TopParentId); |
| | 19 | | // builder.HasOne(e => e.Season).WithMany(e => e.SeasonEpisodes).HasForeignKey(e => e.SeasonId); |
| | 20 | | // builder.HasOne(e => e.Series).WithMany(e => e.SeriesEpisodes).HasForeignKey(e => e.SeriesId); |
| 2 | 21 | | builder.HasMany(e => e.Peoples); |
| 2 | 22 | | builder.HasMany(e => e.UserData); |
| 2 | 23 | | builder.HasMany(e => e.ItemValues); |
| 2 | 24 | | builder.HasMany(e => e.MediaStreams); |
| 2 | 25 | | builder.HasMany(e => e.Chapters); |
| 2 | 26 | | builder.HasMany(e => e.Provider); |
| 2 | 27 | | builder.HasMany(e => e.ParentAncestors); |
| 2 | 28 | | builder.HasMany(e => e.Children); |
| 2 | 29 | | builder.HasMany(e => e.LockedFields); |
| 2 | 30 | | builder.HasMany(e => e.TrailerTypes); |
| 2 | 31 | | builder.HasMany(e => e.Images); |
| | 32 | |
|
| 2 | 33 | | builder.HasIndex(e => e.Path); |
| 2 | 34 | | builder.HasIndex(e => e.ParentId); |
| 2 | 35 | | builder.HasIndex(e => e.PresentationUniqueKey); |
| 2 | 36 | | builder.HasIndex(e => new { e.Id, e.Type, e.IsFolder, e.IsVirtualItem }); |
| | 37 | |
|
| | 38 | | // covering index |
| 2 | 39 | | builder.HasIndex(e => new { e.TopParentId, e.Id }); |
| | 40 | | // series |
| 2 | 41 | | builder.HasIndex(e => new { e.Type, e.SeriesPresentationUniqueKey, e.PresentationUniqueKey, e.SortName }); |
| | 42 | | // series counts |
| | 43 | | // seriesdateplayed sort order |
| 2 | 44 | | builder.HasIndex(e => new { e.Type, e.SeriesPresentationUniqueKey, e.IsFolder, e.IsVirtualItem }); |
| | 45 | | // live tv programs |
| 2 | 46 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.StartDate }); |
| | 47 | | // covering index for getitemvalues |
| 2 | 48 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.Id }); |
| | 49 | | // used by movie suggestions |
| 2 | 50 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.PresentationUniqueKey }); |
| | 51 | | // latest items |
| 2 | 52 | | builder.HasIndex(e => new { e.Type, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated }); |
| 2 | 53 | | builder.HasIndex(e => new { e.IsFolder, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated } |
| | 54 | | // resume |
| 2 | 55 | | builder.HasIndex(e => new { e.MediaType, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey }); |
| 2 | 56 | | } |
| | 57 | | } |