1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Shared serializer in ProviderRepository

[common]

Some caching happens in the serializer settings so best not to
recreate each time
This commit is contained in:
ta264 2020-08-06 21:58:59 +01:00
parent 536c0c19dc
commit d2dcc45492

View File

@ -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
@ -12,9 +14,26 @@ public class ProviderRepository<TProviderDefinition> : BasicRepository<TProvider
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<TProviderDefinition> Query(SqlBuilder builder)
@ -29,7 +48,6 @@ protected override List<TProviderDefinition> Query(SqlBuilder builder)
{
var parser = reader.GetRowParser<TProviderDefinition>(typeof(TProviderDefinition));
var settingsIndex = reader.GetOrdinal(nameof(ProviderDefinition.Settings));
var serializerSettings = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
while (reader.Read())
{
@ -43,7 +61,7 @@ protected override List<TProviderDefinition> Query(SqlBuilder builder)
}
else
{
item.Settings = (IProviderConfig)JsonSerializer.Deserialize(body, impType, serializerSettings);
item.Settings = (IProviderConfig)JsonSerializer.Deserialize(body, impType, _serializerSettings);
}
results.Add(item);