BaseItemConfiguration.cs 2.7 KB

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