diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_files.cs b/src/NzbDrone.Core.Test/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_filesFixture.cs similarity index 100% rename from src/NzbDrone.Core.Test/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_files.cs rename to src/NzbDrone.Core.Test/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_filesFixture.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_files.cs b/src/NzbDrone.Core/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_files.cs index 1c8007853..b49bfaae5 100644 --- a/src/NzbDrone.Core/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_files.cs +++ b/src/NzbDrone.Core/Datastore/Migration/195_parse_language_tags_from_existing_subtitle_files.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Text.Json; using System.Text.Json.Serialization; +using Dapper; using FluentMigrator; using NzbDrone.Core.Datastore.Migration.Framework; using NzbDrone.Core.Parser; @@ -19,7 +20,7 @@ namespace NzbDrone.Core.Datastore.Migration private void UpdateLanguageTags(IDbConnection conn, IDbTransaction tran) { - var updatedLanguageTags = new Dictionary>(); + var updatedLanguageTags = new List(); var now = DateTime.Now; using (var cmd = conn.CreateCommand()) @@ -34,7 +35,11 @@ namespace NzbDrone.Core.Datastore.Migration var relativePath = reader.GetString(1); var languageTags = LanguageParser.ParseLanguageTags(relativePath); - updatedLanguageTags.Add(id, languageTags); + updatedLanguageTags.Add(new + { + Id = id, + LanguageTags = languageTags + }); } } @@ -48,28 +53,8 @@ namespace NzbDrone.Core.Datastore.Migration WriteIndented = true }; - foreach (var pair in updatedLanguageTags) - { - using (var updateCmd = conn.CreateCommand()) - { - updateCmd.Transaction = tran; - - if (conn.GetType().FullName == "Npgsql.NpgsqlConnection") - { - updateCmd.CommandText = "UPDATE \"SubtitleFiles\" SET \"LanguageTags\" = $1, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = $2"; - } - else - { - updateCmd.CommandText = "UPDATE \"SubtitleFiles\" SET \"LanguageTags\" = ?, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = ?"; - } - - updateCmd.AddParameter(JsonSerializer.Serialize(pair.Value, serializerSettings)); - - updateCmd.AddParameter(pair.Key); - - updateCmd.ExecuteNonQuery(); - } - } + var updateSubtitleFilesSql = "UPDATE \"SubtitleFiles\" SET \"LanguageTags\" = @LanguageTags, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = @Id"; + conn.Execute(updateSubtitleFilesSql, updatedLanguageTags, transaction: tran); } } }