mirror of https://github.com/Radarr/Radarr
Fixed: Shared serializer in ProviderRepository
Some caching happens in the serializer settings so best not to
recreate each time
(cherry picked from commit d2dcc45492
)
This commit is contained in:
parent
f1bb8eeb8e
commit
ed2568187e
|
@ -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<TProviderDefinition> : BasicRepository<TProviderDefinition>, IProviderRepository<TProviderDefinition>
|
||||
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)
|
||||
|
@ -28,7 +47,6 @@ namespace NzbDrone.Core.ThingiProvider
|
|||
{
|
||||
var parser = reader.GetRowParser<TProviderDefinition>(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);
|
||||
|
|
Loading…
Reference in New Issue