mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 02:22:31 +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:
parent
536c0c19dc
commit
d2dcc45492
@ -1,9 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Reflection;
|
using NzbDrone.Common.Reflection;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
using NzbDrone.Core.Datastore.Converters;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
|
||||||
namespace NzbDrone.Core.ThingiProvider
|
namespace NzbDrone.Core.ThingiProvider
|
||||||
@ -12,9 +14,26 @@ public class ProviderRepository<TProviderDefinition> : BasicRepository<TProvider
|
|||||||
where TProviderDefinition : ProviderDefinition,
|
where TProviderDefinition : ProviderDefinition,
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
|
protected readonly JsonSerializerOptions _serializerSettings;
|
||||||
|
|
||||||
protected ProviderRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
protected ProviderRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||||
: base(database, 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)
|
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 parser = reader.GetRowParser<TProviderDefinition>(typeof(TProviderDefinition));
|
||||||
var settingsIndex = reader.GetOrdinal(nameof(ProviderDefinition.Settings));
|
var settingsIndex = reader.GetOrdinal(nameof(ProviderDefinition.Settings));
|
||||||
var serializerSettings = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
@ -43,7 +61,7 @@ protected override List<TProviderDefinition> Query(SqlBuilder builder)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item.Settings = (IProviderConfig)JsonSerializer.Deserialize(body, impType, serializerSettings);
|
item.Settings = (IProviderConfig)JsonSerializer.Deserialize(body, impType, _serializerSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
results.Add(item);
|
results.Add(item);
|
||||||
|
Loading…
Reference in New Issue
Block a user