New: Config file setting to disable log database

(cherry picked from commit 92eab4b2e26741b7f20b6b7177418402cb15a3aa)
pull/5230/head
Jared 8 months ago committed by Bogdan
parent 14716a1405
commit cc409d50f5

@ -2,6 +2,7 @@ using Lidarr.Http;
using Lidarr.Http.Extensions; using Lidarr.Http.Extensions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;
namespace Lidarr.Api.V1.Logs namespace Lidarr.Api.V1.Logs
@ -10,16 +11,23 @@ namespace Lidarr.Api.V1.Logs
public class LogController : Controller public class LogController : Controller
{ {
private readonly ILogService _logService; private readonly ILogService _logService;
private readonly IConfigFileProvider _configFileProvider;
public LogController(ILogService logService) public LogController(ILogService logService, IConfigFileProvider configFileProvider)
{ {
_logService = logService; _logService = logService;
_configFileProvider = configFileProvider;
} }
[HttpGet] [HttpGet]
[Produces("application/json")] [Produces("application/json")]
public PagingResource<LogResource> GetLogs([FromQuery] PagingRequestResource paging, string level) public PagingResource<LogResource> GetLogs([FromQuery] PagingRequestResource paging, string level)
{ {
if (!_configFileProvider.LogDbEnabled)
{
return new PagingResource<LogResource>();
}
var pagingResource = new PagingResource<LogResource>(paging); var pagingResource = new PagingResource<LogResource>(paging);
var pageSpec = pagingResource.MapToPagingSpec<LogResource, Log>(); var pageSpec = pagingResource.MapToPagingSpec<LogResource, Log>();

@ -3,6 +3,7 @@ using System.Linq;
using Lidarr.Http; using Lidarr.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Update; using NzbDrone.Core.Update;
using NzbDrone.Core.Update.History; using NzbDrone.Core.Update.History;
@ -13,11 +14,13 @@ namespace Lidarr.Api.V1.Update
{ {
private readonly IRecentUpdateProvider _recentUpdateProvider; private readonly IRecentUpdateProvider _recentUpdateProvider;
private readonly IUpdateHistoryService _updateHistoryService; private readonly IUpdateHistoryService _updateHistoryService;
private readonly IConfigFileProvider _configFileProvider;
public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService) public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService, IConfigFileProvider configFileProvider)
{ {
_recentUpdateProvider = recentUpdateProvider; _recentUpdateProvider = recentUpdateProvider;
_updateHistoryService = updateHistoryService; _updateHistoryService = updateHistoryService;
_configFileProvider = configFileProvider;
} }
[HttpGet] [HttpGet]
@ -45,7 +48,13 @@ namespace Lidarr.Api.V1.Update
installed.Installed = true; installed.Installed = true;
} }
var installDates = _updateHistoryService.InstalledSince(resources.Last().ReleaseDate) if (!_configFileProvider.LogDbEnabled)
{
return resources;
}
var updateHistory = _updateHistoryService.InstalledSince(resources.Last().ReleaseDate);
var installDates = updateHistory
.DistinctBy(v => v.Version) .DistinctBy(v => v.Version)
.ToDictionary(v => v.Version); .ToDictionary(v => v.Version);

@ -21,7 +21,7 @@ namespace Lidarr.Http
public string SortKey { get; set; } public string SortKey { get; set; }
public SortDirection SortDirection { get; set; } public SortDirection SortDirection { get; set; }
public int TotalRecords { get; set; } public int TotalRecords { get; set; }
public List<TResource> Records { get; set; } public List<TResource> Records { get; set; } = new ();
public PagingResource() public PagingResource()
{ {

@ -30,6 +30,7 @@ namespace NzbDrone.Common.Test
.AddNzbDroneLogger() .AddNzbDroneLogger()
.AutoAddServices(Bootstrap.ASSEMBLIES) .AutoAddServices(Bootstrap.ASSEMBLIES)
.AddDummyDatabase() .AddDummyDatabase()
.AddDummyLogDatabase()
.AddStartupContext(new StartupContext("first", "second")); .AddStartupContext(new StartupContext("first", "second"));
container.RegisterInstance(new Mock<IHostLifetime>().Object); container.RegisterInstance(new Mock<IHostLifetime>().Object);

@ -13,4 +13,5 @@ public class LogOptions
public string SyslogServer { get; set; } public string SyslogServer { get; set; }
public int? SyslogPort { get; set; } public int? SyslogPort { get; set; }
public string SyslogLevel { get; set; } public string SyslogLevel { get; set; }
public bool? DbEnabled { get; set; }
} }

@ -57,6 +57,7 @@ namespace NzbDrone.Core.Configuration
string SyslogServer { get; } string SyslogServer { get; }
int SyslogPort { get; } int SyslogPort { get; }
string SyslogLevel { get; } string SyslogLevel { get; }
bool LogDbEnabled { get; }
string Theme { get; } string Theme { get; }
string PostgresHost { get; } string PostgresHost { get; }
int PostgresPort { get; } int PostgresPort { get; }
@ -238,7 +239,7 @@ namespace NzbDrone.Core.Configuration
public string PostgresMainDb => _postgresOptions?.MainDb ?? GetValue("PostgresMainDb", "lidarr-main", persist: false); public string PostgresMainDb => _postgresOptions?.MainDb ?? GetValue("PostgresMainDb", "lidarr-main", persist: false);
public string PostgresLogDb => _postgresOptions?.LogDb ?? GetValue("PostgresLogDb", "lidarr-log", persist: false); public string PostgresLogDb => _postgresOptions?.LogDb ?? GetValue("PostgresLogDb", "lidarr-log", persist: false);
public int PostgresPort => (_postgresOptions?.Port ?? 0) != 0 ? _postgresOptions.Port : GetValueInt("PostgresPort", 5432, 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 bool LogSql => _logOptions.Sql ?? GetValueBoolean("LogSql", false, persist: false);
public int LogRotate => _logOptions.Rotate ?? GetValueInt("LogRotate", 50, persist: false); public int LogRotate => _logOptions.Rotate ?? GetValueInt("LogRotate", 50, persist: false);
public int LogSizeLimit => Math.Min(Math.Max(_logOptions.SizeLimit ?? GetValueInt("LogSizeLimit", 1, persist: false), 0), 10); public int LogSizeLimit => Math.Min(Math.Max(_logOptions.SizeLimit ?? GetValueInt("LogSizeLimit", 1, persist: false), 0), 10);

@ -8,6 +8,12 @@ namespace NzbDrone.Core.Datastore.Extensions
public static IContainer AddDatabase(this IContainer container) public static IContainer AddDatabase(this IContainer container)
{ {
container.RegisterDelegate<IDbFactory, IMainDatabase>(f => new MainDatabase(f.Create()), Reuse.Singleton); 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); container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
return container; return container;
@ -16,6 +22,12 @@ namespace NzbDrone.Core.Datastore.Extensions
public static IContainer AddDummyDatabase(this IContainer container) public static IContainer AddDummyDatabase(this IContainer container)
{ {
container.RegisterInstance<IMainDatabase>(new MainDatabase(null)); container.RegisterInstance<IMainDatabase>(new MainDatabase(null));
return container;
}
public static IContainer AddDummyLogDatabase(this IContainer container)
{
container.RegisterInstance<ILogDatabase>(new LogDatabase(null)); container.RegisterInstance<ILogDatabase>(new LogDatabase(null));
return container; return container;

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using NLog; using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Update.History.Events; using NzbDrone.Core.Update.History.Events;
@ -18,13 +19,15 @@ namespace NzbDrone.Core.Update.History
{ {
private readonly IUpdateHistoryRepository _repository; private readonly IUpdateHistoryRepository _repository;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly IConfigFileProvider _configFileProvider;
private readonly Logger _logger; private readonly Logger _logger;
private Version _prevVersion; private Version _prevVersion;
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger) public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, IConfigFileProvider configFileProvider, Logger logger)
{ {
_repository = repository; _repository = repository;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_configFileProvider = configFileProvider;
_logger = logger; _logger = logger;
} }
@ -58,7 +61,7 @@ namespace NzbDrone.Core.Update.History
public void Handle(ApplicationStartedEvent message) 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 // Don't save dev versions, they change constantly
return; return;

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Update
{ {
var branch = _configFileProvider.Branch; var branch = _configFileProvider.Branch;
var version = BuildInfo.Version; var version = BuildInfo.Version;
var prevVersion = _updateHistoryService.PreviouslyInstalled(); var prevVersion = _configFileProvider.LogDbEnabled ? _updateHistoryService.PreviouslyInstalled() : null;
return _updatePackageProvider.GetRecentUpdates(branch, version, prevVersion); return _updatePackageProvider.GetRecentUpdates(branch, version, prevVersion);
} }
} }

@ -94,6 +94,15 @@ namespace NzbDrone.Host
.AddStartupContext(startupContext) .AddStartupContext(startupContext)
.Resolve<UtilityModeRouter>() .Resolve<UtilityModeRouter>()
.Route(appMode); .Route(appMode);
if (config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true))
{
c.AddLogDatabase();
}
else
{
c.AddDummyLogDatabase();
}
}) })
.ConfigureServices(services => .ConfigureServices(services =>
{ {
@ -139,6 +148,7 @@ namespace NzbDrone.Host
var enableSsl = config.GetValue<bool?>($"Lidarr:Server:{nameof(ServerOptions.EnableSsl)}") ?? config.GetValue(nameof(ConfigFileProvider.EnableSsl), false); var enableSsl = config.GetValue<bool?>($"Lidarr:Server:{nameof(ServerOptions.EnableSsl)}") ?? config.GetValue(nameof(ConfigFileProvider.EnableSsl), false);
var sslCertPath = config.GetValue<string>($"Lidarr:Server:{nameof(ServerOptions.SslCertPath)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath)); var sslCertPath = config.GetValue<string>($"Lidarr:Server:{nameof(ServerOptions.SslCertPath)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath));
var sslCertPassword = config.GetValue<string>($"Lidarr:Server:{nameof(ServerOptions.SslCertPassword)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword)); var sslCertPassword = config.GetValue<string>($"Lidarr:Server:{nameof(ServerOptions.SslCertPassword)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword));
var logDbEnabled = config.GetValue<bool?>($"Lidarr:Log:{nameof(LogOptions.DbEnabled)}") ?? config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true);
var urls = new List<string> { BuildUrl("http", bindAddress, port) }; var urls = new List<string> { BuildUrl("http", bindAddress, port) };
@ -156,6 +166,15 @@ namespace NzbDrone.Host
.AddNzbDroneLogger() .AddNzbDroneLogger()
.AddDatabase() .AddDatabase()
.AddStartupContext(context); .AddStartupContext(context);
if (logDbEnabled)
{
c.AddLogDatabase();
}
else
{
c.AddDummyLogDatabase();
}
}) })
.ConfigureServices(services => .ConfigureServices(services =>
{ {

@ -239,9 +239,13 @@ namespace NzbDrone.Host
// instantiate the databases to initialize/migrate them // instantiate the databases to initialize/migrate them
_ = mainDatabaseFactory.Value; _ = mainDatabaseFactory.Value;
_ = logDatabaseFactory.Value;
if (configFileProvider.LogDbEnabled)
{
_ = logDatabaseFactory.Value;
dbTarget.Register(); dbTarget.Register();
}
SchemaBuilder.Initialize(container); SchemaBuilder.Initialize(container);
if (OsInfo.IsNotWindows) if (OsInfo.IsNotWindows)

Loading…
Cancel
Save