From ed2568187edd86204f9300eb3d19ad5f49ce5996 Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 6 Aug 2020 21:58:59 +0100 Subject: [PATCH] Fixed: Shared serializer in ProviderRepository Some caching happens in the serializer settings so best not to recreate each time (cherry picked from commit d2dcc45492cdd3879c91231a40f5f8a7c3d179a8) --- .../ThingiProvider/ProviderRepository.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/ThingiProvider/ProviderRepository.cs b/src/NzbDrone.Core/ThingiProvider/ProviderRepository.cs index 66bbe559a..71e134ca8 100644 --- a/src/NzbDrone.Core/ThingiProvider/ProviderRepository.cs +++ b/src/NzbDrone.Core/ThingiProvider/ProviderRepository.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; using System.Text.Json; +using System.Text.Json.Serialization; using Dapper; using NzbDrone.Common.Extensions; using NzbDrone.Common.Reflection; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore.Converters; using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.ThingiProvider @@ -11,9 +13,26 @@ namespace NzbDrone.Core.ThingiProvider public class ProviderRepository : BasicRepository, IProviderRepository where TProviderDefinition : ProviderDefinition, new() { + protected readonly JsonSerializerOptions _serializerSettings; + protected ProviderRepository(IMainDatabase database, IEventAggregator eventAggregator) : base(database, eventAggregator) { + var serializerSettings = new JsonSerializerOptions + { + AllowTrailingCommas = true, + IgnoreNullValues = true, + PropertyNameCaseInsensitive = true, + DictionaryKeyPolicy = JsonNamingPolicy.CamelCase, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = true + }; + + serializerSettings.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, true)); + serializerSettings.Converters.Add(new TimeSpanConverter()); + serializerSettings.Converters.Add(new UtcConverter()); + + _serializerSettings = serializerSettings; } protected override List Query(SqlBuilder builder) @@ -28,7 +47,6 @@ namespace NzbDrone.Core.ThingiProvider { var parser = reader.GetRowParser(typeof(TProviderDefinition)); var settingsIndex = reader.GetOrdinal(nameof(ProviderDefinition.Settings)); - var serializerSettings = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; while (reader.Read()) { @@ -42,7 +60,7 @@ namespace NzbDrone.Core.ThingiProvider } else { - item.Settings = (IProviderConfig)JsonSerializer.Deserialize(body, impType, serializerSettings); + item.Settings = (IProviderConfig)JsonSerializer.Deserialize(body, impType, _serializerSettings); } results.Add(item);