From 3a6501abe0d2ea4b7b8f19bfffd95467fce555b8 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 21 Dec 2020 17:28:06 -0700 Subject: [PATCH] Fix another key collision in MigrateDisplayPreferencesDatabase --- .../Routines/MigrateDisplayPreferencesDb.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs index dd005b7f47..f4040748d7 100644 --- a/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs +++ b/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs @@ -8,7 +8,6 @@ using System.Text.Json.Serialization; using Jellyfin.Data.Entities; using Jellyfin.Data.Enums; using Jellyfin.Server.Implementations; -using MediaBrowser.Common.Extensions; using MediaBrowser.Controller; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Entities; @@ -81,7 +80,8 @@ namespace Jellyfin.Server.Migrations.Routines { "unstable", ChromecastVersion.Unstable } }; - var customDisplayPrefs = new HashSet(); + var displayPrefs = new HashSet(StringComparer.OrdinalIgnoreCase); + var customDisplayPrefs = new HashSet(StringComparer.OrdinalIgnoreCase); var dbFilePath = Path.Combine(_paths.DataPath, DbFilename); using (var connection = SQLite3.Open(dbFilePath, ConnectionFlags.ReadOnly, null)) { @@ -98,6 +98,15 @@ namespace Jellyfin.Server.Migrations.Routines var itemId = new Guid(result[1].ToBlob()); var dtoUserId = new Guid(result[1].ToBlob()); + var client = result[2].ToString(); + var displayPreferencesKey = $"{dtoUserId}|{itemId}|{client}"; + if (displayPrefs.Contains(displayPreferencesKey)) + { + // Duplicate display preference. + continue; + } + + displayPrefs.Add(displayPreferencesKey); var existingUser = _userManager.GetUserById(dtoUserId); if (existingUser == null) { @@ -110,7 +119,7 @@ namespace Jellyfin.Server.Migrations.Routines : ChromecastVersion.Stable; dto.CustomPrefs.Remove("chromecastVersion"); - var displayPreferences = new DisplayPreferences(dtoUserId, itemId, result[2].ToString()) + var displayPreferences = new DisplayPreferences(dtoUserId, itemId, client) { IndexBy = Enum.TryParse(dto.IndexBy, true, out var indexBy) ? indexBy : (IndexingKind?)null, ShowBackdrop = dto.ShowBackdrop,