diff options
| author | crobibero <cody@robibe.ro> | 2020-12-04 16:00:11 -0700 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-12-04 16:00:11 -0700 |
| commit | 3db6ae91f6aa68a1eaf3da3d385b069bdd7721ee (patch) | |
| tree | 7e4092397fdfb1f5c6e33ca5ea464cddb7c90996 /Jellyfin.Server.Implementations | |
| parent | 8d8738835ecc36c6f00157d4131d8200d5dd582a (diff) | |
Add ItemId to all display preferences
Diffstat (limited to 'Jellyfin.Server.Implementations')
| -rw-r--r-- | Jellyfin.Server.Implementations/JellyfinDb.cs | 4 | ||||
| -rw-r--r-- | Jellyfin.Server.Implementations/Migrations/20201204223655_AddCustomDisplayPreferences.Designer.cs (renamed from Jellyfin.Server.Implementations/Migrations/20201203203707_AddCustomDisplayPreferences.Designer.cs) | 12 | ||||
| -rw-r--r-- | Jellyfin.Server.Implementations/Migrations/20201204223655_AddCustomDisplayPreferences.cs (renamed from Jellyfin.Server.Implementations/Migrations/20201203203707_AddCustomDisplayPreferences.cs) | 42 | ||||
| -rw-r--r-- | Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs | 10 | ||||
| -rw-r--r-- | Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs | 20 |
5 files changed, 71 insertions, 17 deletions
diff --git a/Jellyfin.Server.Implementations/JellyfinDb.cs b/Jellyfin.Server.Implementations/JellyfinDb.cs index a8aa9b319..7f3f83749 100644 --- a/Jellyfin.Server.Implementations/JellyfinDb.cs +++ b/Jellyfin.Server.Implementations/JellyfinDb.cs @@ -153,7 +153,7 @@ namespace Jellyfin.Server.Implementations .IsUnique(false); modelBuilder.Entity<DisplayPreferences>() - .HasIndex(entity => new { entity.UserId, entity.Client }) + .HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client }) .IsUnique(); modelBuilder.Entity<CustomItemDisplayPreferences>() @@ -161,7 +161,7 @@ namespace Jellyfin.Server.Implementations .IsUnique(false); modelBuilder.Entity<CustomItemDisplayPreferences>() - .HasIndex(entity => new { entity.UserId, entity.Client, entity.Key }) + .HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client, entity.Key }) .IsUnique(); } } diff --git a/Jellyfin.Server.Implementations/Migrations/20201203203707_AddCustomDisplayPreferences.Designer.cs b/Jellyfin.Server.Implementations/Migrations/20201204223655_AddCustomDisplayPreferences.Designer.cs index ce3e30b59..10663d065 100644 --- a/Jellyfin.Server.Implementations/Migrations/20201203203707_AddCustomDisplayPreferences.Designer.cs +++ b/Jellyfin.Server.Implementations/Migrations/20201204223655_AddCustomDisplayPreferences.Designer.cs @@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Jellyfin.Server.Implementations.Migrations { [DbContext(typeof(JellyfinDb))] - [Migration("20201203203707_AddCustomDisplayPreferences")] + [Migration("20201204223655_AddCustomDisplayPreferences")] partial class AddCustomDisplayPreferences { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -102,6 +102,9 @@ namespace Jellyfin.Server.Implementations.Migrations .HasMaxLength(32) .HasColumnType("TEXT"); + b.Property<Guid>("ItemId") + .HasColumnType("TEXT"); + b.Property<string>("Key") .IsRequired() .HasColumnType("TEXT"); @@ -117,7 +120,7 @@ namespace Jellyfin.Server.Implementations.Migrations b.HasIndex("UserId"); - b.HasIndex("UserId", "Client", "Key") + b.HasIndex("UserId", "ItemId", "Client", "Key") .IsUnique(); b.ToTable("CustomItemDisplayPreferences"); @@ -147,6 +150,9 @@ namespace Jellyfin.Server.Implementations.Migrations b.Property<int?>("IndexBy") .HasColumnType("INTEGER"); + b.Property<Guid>("ItemId") + .HasColumnType("TEXT"); + b.Property<int>("ScrollDirection") .HasColumnType("INTEGER"); @@ -173,7 +179,7 @@ namespace Jellyfin.Server.Implementations.Migrations b.HasIndex("UserId"); - b.HasIndex("UserId", "Client") + b.HasIndex("UserId", "ItemId", "Client") .IsUnique(); b.ToTable("DisplayPreferences"); diff --git a/Jellyfin.Server.Implementations/Migrations/20201203203707_AddCustomDisplayPreferences.cs b/Jellyfin.Server.Implementations/Migrations/20201204223655_AddCustomDisplayPreferences.cs index a07b26592..fbc0bffa9 100644 --- a/Jellyfin.Server.Implementations/Migrations/20201203203707_AddCustomDisplayPreferences.cs +++ b/Jellyfin.Server.Implementations/Migrations/20201204223655_AddCustomDisplayPreferences.cs @@ -9,6 +9,11 @@ namespace Jellyfin.Server.Implementations.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.DropIndex( + name: "IX_DisplayPreferences_UserId_Client", + schema: "jellyfin", + table: "DisplayPreferences"); + migrationBuilder.AlterColumn<int>( name: "MaxActiveSessions", schema: "jellyfin", @@ -20,6 +25,14 @@ namespace Jellyfin.Server.Implementations.Migrations oldType: "INTEGER", oldNullable: true); + migrationBuilder.AddColumn<Guid>( + name: "ItemId", + schema: "jellyfin", + table: "DisplayPreferences", + type: "TEXT", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); + migrationBuilder.CreateTable( name: "CustomItemDisplayPreferences", schema: "jellyfin", @@ -28,6 +41,7 @@ namespace Jellyfin.Server.Implementations.Migrations Id = table.Column<int>(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), UserId = table.Column<Guid>(type: "TEXT", nullable: false), + ItemId = table.Column<Guid>(type: "TEXT", nullable: false), Client = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false), Key = table.Column<string>(type: "TEXT", nullable: false), Value = table.Column<string>(type: "TEXT", nullable: false) @@ -38,16 +52,23 @@ namespace Jellyfin.Server.Implementations.Migrations }); migrationBuilder.CreateIndex( + name: "IX_DisplayPreferences_UserId_ItemId_Client", + schema: "jellyfin", + table: "DisplayPreferences", + columns: new[] { "UserId", "ItemId", "Client" }, + unique: true); + + migrationBuilder.CreateIndex( name: "IX_CustomItemDisplayPreferences_UserId", schema: "jellyfin", table: "CustomItemDisplayPreferences", column: "UserId"); migrationBuilder.CreateIndex( - name: "IX_CustomItemDisplayPreferences_UserId_Client_Key", + name: "IX_CustomItemDisplayPreferences_UserId_ItemId_Client_Key", schema: "jellyfin", table: "CustomItemDisplayPreferences", - columns: new[] { "UserId", "Client", "Key" }, + columns: new[] { "UserId", "ItemId", "Client", "Key" }, unique: true); } @@ -57,6 +78,16 @@ namespace Jellyfin.Server.Implementations.Migrations name: "CustomItemDisplayPreferences", schema: "jellyfin"); + migrationBuilder.DropIndex( + name: "IX_DisplayPreferences_UserId_ItemId_Client", + schema: "jellyfin", + table: "DisplayPreferences"); + + migrationBuilder.DropColumn( + name: "ItemId", + schema: "jellyfin", + table: "DisplayPreferences"); + migrationBuilder.AlterColumn<int>( name: "MaxActiveSessions", schema: "jellyfin", @@ -65,6 +96,13 @@ namespace Jellyfin.Server.Implementations.Migrations nullable: true, oldClrType: typeof(int), oldType: "INTEGER"); + + migrationBuilder.CreateIndex( + name: "IX_DisplayPreferences_UserId_Client", + schema: "jellyfin", + table: "DisplayPreferences", + columns: new[] { "UserId", "Client" }, + unique: true); } } } diff --git a/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs b/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs index 3b85c911c..1614a88ef 100644 --- a/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs +++ b/Jellyfin.Server.Implementations/Migrations/JellyfinDbModelSnapshot.cs @@ -99,6 +99,9 @@ namespace Jellyfin.Server.Implementations.Migrations .HasMaxLength(32) .HasColumnType("TEXT"); + b.Property<Guid>("ItemId") + .HasColumnType("TEXT"); + b.Property<string>("Key") .IsRequired() .HasColumnType("TEXT"); @@ -114,7 +117,7 @@ namespace Jellyfin.Server.Implementations.Migrations b.HasIndex("UserId"); - b.HasIndex("UserId", "Client", "Key") + b.HasIndex("UserId", "ItemId", "Client", "Key") .IsUnique(); b.ToTable("CustomItemDisplayPreferences"); @@ -144,6 +147,9 @@ namespace Jellyfin.Server.Implementations.Migrations b.Property<int?>("IndexBy") .HasColumnType("INTEGER"); + b.Property<Guid>("ItemId") + .HasColumnType("TEXT"); + b.Property<int>("ScrollDirection") .HasColumnType("INTEGER"); @@ -170,7 +176,7 @@ namespace Jellyfin.Server.Implementations.Migrations b.HasIndex("UserId"); - b.HasIndex("UserId", "Client") + b.HasIndex("UserId", "ItemId", "Client") .IsUnique(); b.ToTable("DisplayPreferences"); diff --git a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs index 1f3b4ff17..c8a589cab 100644 --- a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs +++ b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs @@ -26,16 +26,16 @@ namespace Jellyfin.Server.Implementations.Users } /// <inheritdoc /> - public DisplayPreferences GetDisplayPreferences(Guid userId, string client) + public DisplayPreferences GetDisplayPreferences(Guid userId, Guid itemId, string client) { var prefs = _dbContext.DisplayPreferences .Include(pref => pref.HomeSections) .FirstOrDefault(pref => - pref.UserId == userId && string.Equals(pref.Client, client)); + pref.UserId == userId && string.Equals(pref.Client, client) && pref.ItemId == itemId); if (prefs == null) { - prefs = new DisplayPreferences(userId, client); + prefs = new DisplayPreferences(userId, itemId, client); _dbContext.DisplayPreferences.Add(prefs); } @@ -67,26 +67,30 @@ namespace Jellyfin.Server.Implementations.Users } /// <inheritdoc /> - public IDictionary<string, string> ListCustomItemDisplayPreferences(Guid userId, string client) + public IDictionary<string, string> ListCustomItemDisplayPreferences(Guid userId, Guid itemId, string client) { return _dbContext.CustomItemDisplayPreferences .AsQueryable() - .Where(prefs => prefs.UserId == userId && string.Equals(prefs.Client, client)) + .Where(prefs => prefs.UserId == userId + && prefs.ItemId == itemId + && string.Equals(prefs.Client, client)) .ToDictionary(prefs => prefs.Key, prefs => prefs.Value); } /// <inheritdoc /> - public void SetCustomItemDisplayPreferences(Guid userId, string client, Dictionary<string, string> customPreferences) + public void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary<string, string> customPreferences) { var existingPrefs = _dbContext.CustomItemDisplayPreferences .AsQueryable() - .Where(prefs => prefs.UserId == userId && string.Equals(prefs.Client, client)); + .Where(prefs => prefs.UserId == userId + && prefs.ItemId == itemId + && string.Equals(prefs.Client, client)); _dbContext.CustomItemDisplayPreferences.RemoveRange(existingPrefs); foreach (var (key, value) in customPreferences) { _dbContext.CustomItemDisplayPreferences - .Add(new CustomItemDisplayPreferences(userId, client, key, value)); + .Add(new CustomItemDisplayPreferences(userId, itemId, client, key, value)); } } |
