BaseItemConfiguration.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using Jellyfin.Data.Entities;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  5. using SQLitePCL;
  6. namespace Jellyfin.Server.Implementations.ModelConfiguration;
  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. {
  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);
  21. builder.HasMany(e => e.Peoples);
  22. builder.HasMany(e => e.UserData);
  23. builder.HasMany(e => e.ItemValues);
  24. builder.HasMany(e => e.MediaStreams);
  25. builder.HasMany(e => e.Chapters);
  26. builder.HasMany(e => e.Provider);
  27. builder.HasMany(e => e.ParentAncestors);
  28. builder.HasMany(e => e.Children);
  29. builder.HasMany(e => e.LockedFields);
  30. builder.HasMany(e => e.TrailerTypes);
  31. builder.HasMany(e => e.Images);
  32. builder.HasIndex(e => e.Path);
  33. builder.HasIndex(e => e.ParentId);
  34. builder.HasIndex(e => e.PresentationUniqueKey);
  35. builder.HasIndex(e => new { e.Id, e.Type, e.IsFolder, e.IsVirtualItem });
  36. // covering index
  37. builder.HasIndex(e => new { e.TopParentId, e.Id });
  38. // series
  39. builder.HasIndex(e => new { e.Type, e.SeriesPresentationUniqueKey, e.PresentationUniqueKey, e.SortName });
  40. // series counts
  41. // seriesdateplayed sort order
  42. builder.HasIndex(e => new { e.Type, e.SeriesPresentationUniqueKey, e.IsFolder, e.IsVirtualItem });
  43. // live tv programs
  44. builder.HasIndex(e => new { e.Type, e.TopParentId, e.StartDate });
  45. // covering index for getitemvalues
  46. builder.HasIndex(e => new { e.Type, e.TopParentId, e.Id });
  47. // used by movie suggestions
  48. builder.HasIndex(e => new { e.Type, e.TopParentId, e.PresentationUniqueKey });
  49. // latest items
  50. builder.HasIndex(e => new { e.Type, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated });
  51. builder.HasIndex(e => new { e.IsFolder, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey, e.DateCreated });
  52. // resume
  53. builder.HasIndex(e => new { e.MediaType, e.TopParentId, e.IsVirtualItem, e.PresentationUniqueKey });
  54. }
  55. }