Skip to content

Commit

Permalink
refactor: pull changes from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
sillock1 committed May 5, 2024
1 parent 46a7dcd commit caaa91e
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/NzbDrone.Common/Options/LogOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
2 changes: 2 additions & 0 deletions src/NzbDrone.Core/Configuration/ConfigFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>,
string SyslogServer { get; }
int SyslogPort { get; }
string SyslogLevel { get; }
bool LogDbEnabled { get; }
string PostgresHost { get; }
int PostgresPort { get; }
string PostgresUser { get; }
Expand Down Expand Up @@ -229,6 +230,7 @@ public AuthenticationType AuthenticationMethod
public string PostgresMainDb => _postgresOptions?.MainDb ?? GetValue("PostgresMainDb", "radarr-main", persist: false);
public string PostgresLogDb => _postgresOptions?.LogDb ?? GetValue("PostgresLogDb", "radarr-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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public static class CompositionExtensions
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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/NzbDrone.Core/Update/History/UpdateHistoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public class UpdateHistoryService : IUpdateHistoryService, IHandle<ApplicationSt
{
private readonly IUpdateHistoryRepository _repository;
private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger;
private readonly IConfigFileProvider _configFileProvider;
private readonly Logger _logger;
private Version _prevVersion;

public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger, IConfigFileProvider configFileProvider)
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, IConfigFileProvider configFileProvider, Logger logger)
{
_repository = repository;
_eventAggregator = eventAggregator;
_logger = logger;
_configFileProvider = configFileProvider;
_logger = logger;
}

public Version PreviouslyInstalled()
Expand Down
2 changes: 1 addition & 1 deletion src/NzbDrone.Core/Update/RecentUpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public List<UpdatePackage> GetRecentUpdatePackages()
{
var branch = _configFileProvider.Branch;
var version = BuildInfo.Version;
var prevVersion = _updateHistoryService.PreviouslyInstalled();
var prevVersion = _configFileProvider.LogDbEnabled ? _updateHistoryService.PreviouslyInstalled() : null;
return _updatePackageProvider.GetRecentUpdates(branch, version, prevVersion);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/NzbDrone.Host.Test/ContainerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void SetUp()
.AutoAddServices(Bootstrap.ASSEMBLIES)
.AddNzbDroneLogger()
.AddDummyDatabase()
.AddDummyLogDatabase()
.AddStartupContext(args);

// dummy lifetime and broadcaster so tests resolve
Expand Down
19 changes: 19 additions & 0 deletions src/NzbDrone.Host/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public static void Start(string[] args, Action<IHostBuilder> trayCallback = null
.AddStartupContext(startupContext)
.Resolve<UtilityModeRouter>()
.Route(appMode);
if (config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true))
{
c.AddLogDatabase();
}
else
{
c.AddDummyLogDatabase();
}
})
.ConfigureServices(services =>
{
Expand Down Expand Up @@ -135,6 +144,7 @@ public static IHostBuilder CreateConsoleHostBuilder(string[] args, StartupContex
var enableSsl = config.GetValue<bool?>($"Radarr:Server:{nameof(ServerOptions.EnableSsl)}") ?? config.GetValue(nameof(ConfigFileProvider.EnableSsl), false);
var sslCertPath = config.GetValue<string>($"Radarr:Server:{nameof(ServerOptions.SslCertPath)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath));
var sslCertPassword = config.GetValue<string>($"Radarr:Server:{nameof(ServerOptions.SslCertPassword)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword));
var logDbEnabled = config.GetValue<bool?>($"Radarr:Log:{nameof(LogOptions.DbEnabled)}") ?? config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true);

var urls = new List<string> { BuildUrl("http", bindAddress, port) };

Expand All @@ -152,6 +162,15 @@ public static IHostBuilder CreateConsoleHostBuilder(string[] args, StartupContex
.AddNzbDroneLogger()
.AddDatabase()
.AddStartupContext(context);
if (logDbEnabled)
{
c.AddLogDatabase();
}
else
{
c.AddDummyLogDatabase();
}
})
.ConfigureServices(services =>
{
Expand Down
8 changes: 6 additions & 2 deletions src/NzbDrone.Host/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,13 @@ public void ConfigureServices(IServiceCollection services)

// instantiate the databases to initialize/migrate them
_ = mainDatabaseFactory.Value;
_ = logDatabaseFactory.Value;

dbTarget.Register();
if (configFileProvider.LogDbEnabled)
{
_ = logDatabaseFactory.Value;
dbTarget.Register();
}

SchemaBuilder.Initialize(container);

if (OsInfo.IsNotWindows)
Expand Down
12 changes: 9 additions & 3 deletions src/Radarr.Api.V3/Logs/LogController.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Instrumentation;
using Radarr.Http;
using Radarr.Http.Extensions;
using Radarr.Http.REST.Filters;

namespace Radarr.Api.V3.Logs
{
[V3ApiController]
[LogDatabaseDisabledActionFilter]
public class LogController : Controller
{
private readonly ILogService _logService;
private readonly IConfigFileProvider _configFileProvider;

public LogController(ILogService logService)
public LogController(ILogService logService, IConfigFileProvider configFileProvider)
{
_logService = logService;
_configFileProvider = configFileProvider;
}

[HttpGet]
[Produces("application/json")]
public PagingResource<LogResource> GetLogs([FromQuery] PagingRequestResource paging, string level)
{
if (!_configFileProvider.LogDbEnabled)
{
return new PagingResource<LogResource>();
}

var pagingResource = new PagingResource<LogResource>(paging);
var pageSpec = pagingResource.MapToPagingSpec<LogResource, Log>();

Expand Down
19 changes: 13 additions & 6 deletions src/Radarr.Api.V3/Update/UpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Update;
using NzbDrone.Core.Update.History;
using Radarr.Http;
using Radarr.Http.REST.Filters;

namespace Radarr.Api.V3.Update
{
[V3ApiController]
[LogDatabaseDisabledActionFilter]
public class UpdateController : Controller
{
private readonly IRecentUpdateProvider _recentUpdateProvider;
private readonly IUpdateHistoryService _updateHistoryService;
private readonly IConfigFileProvider _configFileProvider;

public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService)
public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService, IConfigFileProvider configFileProvider)
{
_recentUpdateProvider = recentUpdateProvider;
_updateHistoryService = updateHistoryService;
_configFileProvider = configFileProvider;
}

[HttpGet]
Expand All @@ -46,9 +47,15 @@ public List<UpdateResource> GetRecentUpdates()
installed.Installed = true;
}

var installDates = _updateHistoryService.InstalledSince(resources.Last().ReleaseDate)
.DistinctBy(v => v.Version)
.ToDictionary(v => v.Version);
if (!_configFileProvider.LogDbEnabled)
{
return resources;
}

var updateHistory = _updateHistoryService.InstalledSince(resources.Last().ReleaseDate);
var installDates = updateHistory
.DistinctBy(v => v.Version)
.ToDictionary(v => v.Version);

foreach (var resource in resources)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Radarr.Http/PagingResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PagingResource<TResource>
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()
{
Expand Down

This file was deleted.

0 comments on commit caaa91e

Please sign in to comment.