diff options
| author | Patrick Barron <barronpm@gmail.com> | 2021-03-18 20:09:11 -0400 |
|---|---|---|
| committer | Patrick Barron <barronpm@gmail.com> | 2021-03-25 19:51:27 -0400 |
| commit | 3c4187e7803afd1d95eac20b30d2063ca2134413 (patch) | |
| tree | e9ab2ba9eec87ba76911f0a4565f408774002cb1 | |
| parent | f1cadb27d9d6ddbb2d42777e4c546a73bd5bcfe3 (diff) | |
Add indexes for user permissions and preferences
| -rw-r--r-- | Jellyfin.Server.Implementations/JellyfinDb.cs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/JellyfinDb.cs b/Jellyfin.Server.Implementations/JellyfinDb.cs index 88ed22086..a2eaea3ca 100644 --- a/Jellyfin.Server.Implementations/JellyfinDb.cs +++ b/Jellyfin.Server.Implementations/JellyfinDb.cs @@ -174,6 +174,7 @@ namespace Jellyfin.Server.Implementations .WithOne() .OnDelete(DeleteBehavior.Cascade); + modelBuilder.Entity<DisplayPreferences>() .HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client }) .IsUnique(); @@ -181,6 +182,19 @@ namespace Jellyfin.Server.Implementations modelBuilder.Entity<CustomItemDisplayPreferences>() .HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client, entity.Key }) .IsUnique(); + + // Used to get a user's permissions or a specific permission for a user. + // Also prevents multiple values being created for a user. + // Filtered over non-null user ids for when other entities (groups, API keys) get permissions + modelBuilder.Entity<Permission>() + .HasIndex(p => new { p.UserId, p.Kind }) + .HasFilter("[UserId] IS NOT NULL") + .IsUnique(); + + modelBuilder.Entity<Preference>() + .HasIndex(p => new { p.UserId, p.Kind }) + .HasFilter("[UserId] IS NOT NULL") + .IsUnique(); } } } |
