mirror of https://github.com/Sonarr/Sonarr
New: config flag to disable log database
This commit is contained in:
parent
c81ae65461
commit
87735b5805
|
@ -30,6 +30,7 @@ namespace NzbDrone.Common.Test
|
|||
.AddNzbDroneLogger()
|
||||
.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||
.AddDummyDatabase()
|
||||
.AddDummyLogDatabase()
|
||||
.AddStartupContext(new StartupContext("first", "second"));
|
||||
|
||||
container.RegisterInstance(new Mock<IHostLifetime>().Object);
|
||||
|
|
|
@ -11,4 +11,5 @@ public class LogOptions
|
|||
public string SyslogServer { get; set; }
|
||||
public int? SyslogPort { get; set; }
|
||||
public string SyslogLevel { get; set; }
|
||||
public bool? DbEnabled { get; set; }
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace NzbDrone.Core.Configuration
|
|||
string SyslogServer { get; }
|
||||
int SyslogPort { get; }
|
||||
string SyslogLevel { get; }
|
||||
bool LogDbEnabled { get; }
|
||||
string Theme { get; }
|
||||
string PostgresHost { get; }
|
||||
int PostgresPort { get; }
|
||||
|
@ -230,7 +231,7 @@ namespace NzbDrone.Core.Configuration
|
|||
public string PostgresMainDb => _postgresOptions?.MainDb ?? GetValue("PostgresMainDb", "sonarr-main", persist: false);
|
||||
public string PostgresLogDb => _postgresOptions?.LogDb ?? GetValue("PostgresLogDb", "sonarr-log", persist: false);
|
||||
public int PostgresPort => (_postgresOptions?.Port ?? 0) != 0 ? _postgresOptions.Port : GetValueInt("PostgresPort", 5432, persist: false);
|
||||
|
||||
public bool LogDbEnabled => _logOptions.DbEnabled ?? GetValueBoolean("LogDbEnabled", true, persist: false);
|
||||
public bool LogSql => _logOptions.Sql ?? GetValueBoolean("LogSql", false, persist: false);
|
||||
public int LogRotate => _logOptions.Rotate ?? GetValueInt("LogRotate", 50, persist: false);
|
||||
public bool FilterSentryEvents => _logOptions.FilterSentryEvents ?? GetValueBoolean("FilterSentryEvents", true, persist: false);
|
||||
|
|
|
@ -8,6 +8,12 @@ namespace NzbDrone.Core.Datastore.Extensions
|
|||
public static IContainer AddDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterDelegate<IDbFactory, IMainDatabase>(f => new MainDatabase(f.Create()), Reuse.Singleton);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public static IContainer AddLogDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
|
||||
|
||||
return container;
|
||||
|
@ -16,6 +22,12 @@ namespace NzbDrone.Core.Datastore.Extensions
|
|||
public static IContainer AddDummyDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterInstance<IMainDatabase>(new MainDatabase(null));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public static IContainer AddDummyLogDatabase(this IContainer container)
|
||||
{
|
||||
container.RegisterInstance<ILogDatabase>(new LogDatabase(null));
|
||||
|
||||
return container;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Update.History.Events;
|
||||
|
@ -19,13 +20,15 @@ namespace NzbDrone.Core.Update.History
|
|||
private readonly IUpdateHistoryRepository _repository;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private Version _prevVersion;
|
||||
|
||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger)
|
||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger, IConfigFileProvider configFileProvider)
|
||||
{
|
||||
_repository = repository;
|
||||
_eventAggregator = eventAggregator;
|
||||
_logger = logger;
|
||||
_configFileProvider = configFileProvider;
|
||||
}
|
||||
|
||||
public Version PreviouslyInstalled()
|
||||
|
@ -58,7 +61,7 @@ namespace NzbDrone.Core.Update.History
|
|||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
if (BuildInfo.Version.Major == 10)
|
||||
if (BuildInfo.Version.Major == 10 || !_configFileProvider.LogDbEnabled)
|
||||
{
|
||||
// Don't save dev versions, they change constantly
|
||||
return;
|
||||
|
|
|
@ -95,6 +95,14 @@ namespace NzbDrone.Host
|
|||
.AddStartupContext(startupContext)
|
||||
.Resolve<UtilityModeRouter>()
|
||||
.Route(appMode);
|
||||
if (config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true))
|
||||
{
|
||||
c.AddLogDatabase();
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AddDummyLogDatabase();
|
||||
}
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
|
@ -131,6 +139,7 @@ namespace NzbDrone.Host
|
|||
var enableSsl = config.GetValue<bool?>($"Sonarr:Server:{nameof(ServerOptions.EnableSsl)}") ?? config.GetValue(nameof(ConfigFileProvider.EnableSsl), false);
|
||||
var sslCertPath = config.GetValue<string>($"Sonarr:Server:{nameof(ServerOptions.SslCertPath)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath));
|
||||
var sslCertPassword = config.GetValue<string>($"Sonarr:Server:{nameof(ServerOptions.SslCertPassword)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword));
|
||||
var logDbEnabled = config.GetValue<bool?>($"Sonarr:Log:{nameof(LogOptions.DbEnabled)}") ?? config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true);
|
||||
|
||||
var urls = new List<string> { BuildUrl("http", bindAddress, port) };
|
||||
|
||||
|
@ -152,6 +161,14 @@ namespace NzbDrone.Host
|
|||
.AddNzbDroneLogger()
|
||||
.AddDatabase()
|
||||
.AddStartupContext(context);
|
||||
if (logDbEnabled)
|
||||
{
|
||||
c.AddLogDatabase();
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AddDummyLogDatabase();
|
||||
}
|
||||
|
||||
SchemaBuilder.Initialize(c);
|
||||
})
|
||||
|
|
|
@ -220,9 +220,12 @@ namespace NzbDrone.Host
|
|||
|
||||
// instantiate the databases to initialize/migrate them
|
||||
_ = mainDatabaseFactory.Value;
|
||||
_ = logDatabaseFactory.Value;
|
||||
|
||||
dbTarget.Register();
|
||||
if (configFileProvider.LogDbEnabled)
|
||||
{
|
||||
_ = logDatabaseFactory.Value;
|
||||
dbTarget.Register();
|
||||
}
|
||||
|
||||
if (OsInfo.IsNotWindows)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,11 @@ using NzbDrone.Common.Extensions;
|
|||
using NzbDrone.Core.Instrumentation;
|
||||
using Sonarr.Http;
|
||||
using Sonarr.Http.Extensions;
|
||||
|
||||
using Sonarr.Http.REST.Filters;
|
||||
namespace Sonarr.Api.V3.Logs
|
||||
{
|
||||
[V3ApiController]
|
||||
[TypeFilter(typeof(LogDatabaseDisabledActionFilterAttribute<PagingResource<LogResource>>))]
|
||||
public class LogController : Controller
|
||||
{
|
||||
private readonly ILogService _logService;
|
||||
|
|
|
@ -5,10 +5,12 @@ using NzbDrone.Common.EnvironmentInfo;
|
|||
using NzbDrone.Core.Update;
|
||||
using NzbDrone.Core.Update.History;
|
||||
using Sonarr.Http;
|
||||
using Sonarr.Http.REST.Filters;
|
||||
|
||||
namespace Sonarr.Api.V3.Update
|
||||
{
|
||||
[V3ApiController]
|
||||
[TypeFilter(typeof(LogDatabaseDisabledActionFilterAttribute<List<UpdateResource>>))]
|
||||
public class UpdateController : Controller
|
||||
{
|
||||
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Sonarr.Http
|
|||
public string SortKey { get; set; }
|
||||
public SortDirection SortDirection { get; set; }
|
||||
public int TotalRecords { get; set; }
|
||||
public List<TResource> Records { get; set; }
|
||||
public List<TResource> Records { get; set; } = new ();
|
||||
|
||||
public PagingResource()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace Sonarr.Http.REST.Filters;
|
||||
|
||||
public class LogDatabaseDisabledActionFilterAttribute<TResult> : IActionFilter
|
||||
where TResult : class, new()
|
||||
{
|
||||
public void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var configFileProvider = context.HttpContext.RequestServices.GetService<IConfigFileProvider>();
|
||||
if (!configFileProvider.LogDbEnabled)
|
||||
{
|
||||
context.Result = new OkObjectResult(new TResult());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue