From 44b063740e7412f92fc9563e3015d1bcb922fc34 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 29 Dec 2024 01:46:28 -0500 Subject: [PATCH 1/5] Add time gate to Nexus OAuth validation to ensure we don't generate an excessive number of requests --- Wabbajack.Networking.NexusApi/NexusApi.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Wabbajack.Networking.NexusApi/NexusApi.cs b/Wabbajack.Networking.NexusApi/NexusApi.cs index 186d724aa..0054534b4 100644 --- a/Wabbajack.Networking.NexusApi/NexusApi.cs +++ b/Wabbajack.Networking.NexusApi/NexusApi.cs @@ -33,7 +33,8 @@ public class NexusApi public readonly ITokenProvider AuthInfo; private DateTime _lastValidated; private (ValidateInfo info, ResponseMetadata header) _lastValidatedInfo; - private AsyncLock _authLock = new(); + private readonly AsyncLock _authLock = new(); + private readonly AsyncLock _authValidationLock = new(); public NexusApi(ITokenProvider authInfo, ILogger logger, HttpClient client, IResource limiter, ApplicationInfo appInfo, JsonSerializerOptions jsonOptions) @@ -53,12 +54,14 @@ public NexusApi(ITokenProvider authInfo, ILogger logg { var (isApi, code) = await GetAuthInfo(); + using var _ = await _authValidationLock.WaitAsync(); + if (isApi) { var msg = await GenerateMessage(HttpMethod.Get, Endpoints.Validate); _lastValidatedInfo = await Send(msg, token); } - else + else if(_lastValidated < DateTime.Now - TimeSpan.FromMinutes(5)) // We don't want to spam the validate endpoint when starting a modlist download { var msg = await GenerateMessage(HttpMethod.Get, Endpoints.OAuthValidate); var (data, header) = await Send(msg, token); @@ -68,9 +71,10 @@ public NexusApi(ITokenProvider authInfo, ILogger logg Name = data.Name, }; _lastValidatedInfo = (validateInfo, header); + + _lastValidated = DateTime.Now; } - _lastValidated = DateTime.Now; return _lastValidatedInfo; } From c9ea411bc8aa80fd837576d8da54de12a8ed65ae Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 29 Dec 2024 07:50:58 -0500 Subject: [PATCH 2/5] Filtering logs --- Wabbajack.App.Wpf/Models/LogStream.cs | 2 ++ Wabbajack.App.Wpf/Views/Common/LogView.xaml | 7 ++++++- Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs | 11 ++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Wabbajack.App.Wpf/Models/LogStream.cs b/Wabbajack.App.Wpf/Models/LogStream.cs index 5a997c017..3dda836cb 100644 --- a/Wabbajack.App.Wpf/Models/LogStream.cs +++ b/Wabbajack.App.Wpf/Models/LogStream.cs @@ -68,6 +68,7 @@ public interface ILogMessage string ShortMessage { get; } DateTime TimeStamp { get; } string LongMessage { get; } + LogLevel Level { get; } } private record LogMessage(LogEventInfo info) : ILogMessage @@ -76,6 +77,7 @@ private record LogMessage(LogEventInfo info) : ILogMessage public string ShortMessage => info.FormattedMessage; public DateTime TimeStamp => info.TimeStamp; public string LongMessage => info.FormattedMessage; + public LogLevel Level => info.Level; } } \ No newline at end of file diff --git a/Wabbajack.App.Wpf/Views/Common/LogView.xaml b/Wabbajack.App.Wpf/Views/Common/LogView.xaml index 3b21e9c95..00e66b989 100644 --- a/Wabbajack.App.Wpf/Views/Common/LogView.xaml +++ b/Wabbajack.App.Wpf/Views/Common/LogView.xaml @@ -14,7 +14,7 @@ local:AutoScrollBehavior.ScrollOnNewItem="True" BorderBrush="Transparent" BorderThickness="1" - ItemsSource="{Binding LoggerProvider.MessageLog}" + ItemsSource="{Binding Source={StaticResource FilteredItems}}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> @@ -22,5 +22,10 @@ + + + diff --git a/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs b/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs index ff853410f..4eff8bf47 100644 --- a/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs +++ b/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs @@ -1,5 +1,8 @@ -using System.Windows; +using Microsoft.Extensions.Logging; +using System.Windows; using System.Windows.Controls; +using System.Windows.Data; +using static Wabbajack.Models.LogStream; namespace Wabbajack { @@ -16,6 +19,12 @@ public double ProgressPercent public static readonly DependencyProperty ProgressPercentProperty = DependencyProperty.Register(nameof(ProgressPercent), typeof(double), typeof(LogView), new FrameworkPropertyMetadata(default(double))); + private void FilteredItems_OnFilter(object sender, FilterEventArgs e) + { + var item = e.Item as ILogMessage; + e.Accepted = item.Level.Ordinal > 4; + } + public LogView() { InitializeComponent(); From 2fb6b6ac224695cba345190310f07b78d78aa6b3 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 29 Dec 2024 07:50:58 -0500 Subject: [PATCH 3/5] Filtering logs --- Wabbajack.App.Wpf/Models/LogStream.cs | 2 ++ Wabbajack.App.Wpf/Views/Common/LogView.xaml | 7 ++++++- Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs | 11 ++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Wabbajack.App.Wpf/Models/LogStream.cs b/Wabbajack.App.Wpf/Models/LogStream.cs index 5a997c017..3dda836cb 100644 --- a/Wabbajack.App.Wpf/Models/LogStream.cs +++ b/Wabbajack.App.Wpf/Models/LogStream.cs @@ -68,6 +68,7 @@ public interface ILogMessage string ShortMessage { get; } DateTime TimeStamp { get; } string LongMessage { get; } + LogLevel Level { get; } } private record LogMessage(LogEventInfo info) : ILogMessage @@ -76,6 +77,7 @@ private record LogMessage(LogEventInfo info) : ILogMessage public string ShortMessage => info.FormattedMessage; public DateTime TimeStamp => info.TimeStamp; public string LongMessage => info.FormattedMessage; + public LogLevel Level => info.Level; } } \ No newline at end of file diff --git a/Wabbajack.App.Wpf/Views/Common/LogView.xaml b/Wabbajack.App.Wpf/Views/Common/LogView.xaml index 3b21e9c95..00e66b989 100644 --- a/Wabbajack.App.Wpf/Views/Common/LogView.xaml +++ b/Wabbajack.App.Wpf/Views/Common/LogView.xaml @@ -14,7 +14,7 @@ local:AutoScrollBehavior.ScrollOnNewItem="True" BorderBrush="Transparent" BorderThickness="1" - ItemsSource="{Binding LoggerProvider.MessageLog}" + ItemsSource="{Binding Source={StaticResource FilteredItems}}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> @@ -22,5 +22,10 @@ + + + diff --git a/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs b/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs index ff853410f..4eff8bf47 100644 --- a/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs +++ b/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs @@ -1,5 +1,8 @@ -using System.Windows; +using Microsoft.Extensions.Logging; +using System.Windows; using System.Windows.Controls; +using System.Windows.Data; +using static Wabbajack.Models.LogStream; namespace Wabbajack { @@ -16,6 +19,12 @@ public double ProgressPercent public static readonly DependencyProperty ProgressPercentProperty = DependencyProperty.Register(nameof(ProgressPercent), typeof(double), typeof(LogView), new FrameworkPropertyMetadata(default(double))); + private void FilteredItems_OnFilter(object sender, FilterEventArgs e) + { + var item = e.Item as ILogMessage; + e.Accepted = item.Level.Ordinal > 4; + } + public LogView() { InitializeComponent(); From c23c7a73d98caa2aeafdc1afe20d1b3b35082535 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 29 Dec 2024 07:56:40 -0500 Subject: [PATCH 4/5] Adjusted logview filtering --- Wabbajack.App.Wpf/Views/Common/LogView.xaml | 10 +++++----- Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Wabbajack.App.Wpf/Views/Common/LogView.xaml b/Wabbajack.App.Wpf/Views/Common/LogView.xaml index 00e66b989..b42443dc3 100644 --- a/Wabbajack.App.Wpf/Views/Common/LogView.xaml +++ b/Wabbajack.App.Wpf/Views/Common/LogView.xaml @@ -9,6 +9,11 @@ d:DesignWidth="800" mc:Ignorable="d"> + + + - - - diff --git a/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs b/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs index 4eff8bf47..1d728cb66 100644 --- a/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs +++ b/Wabbajack.App.Wpf/Views/Common/LogView.xaml.cs @@ -22,7 +22,7 @@ public double ProgressPercent private void FilteredItems_OnFilter(object sender, FilterEventArgs e) { var item = e.Item as ILogMessage; - e.Accepted = item.Level.Ordinal > 4; + e.Accepted = item.Level.Ordinal > 3; } public LogView() From e20fda41cb151db9a29ad6c089e8a6bd9c854714 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 29 Dec 2024 07:58:30 -0500 Subject: [PATCH 5/5] Revert "Add time gate to Nexus OAuth validation to ensure we don't generate an excessive number of requests" This reverts commit 44b063740e7412f92fc9563e3015d1bcb922fc34. --- Wabbajack.Networking.NexusApi/NexusApi.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Wabbajack.Networking.NexusApi/NexusApi.cs b/Wabbajack.Networking.NexusApi/NexusApi.cs index 0054534b4..186d724aa 100644 --- a/Wabbajack.Networking.NexusApi/NexusApi.cs +++ b/Wabbajack.Networking.NexusApi/NexusApi.cs @@ -33,8 +33,7 @@ public class NexusApi public readonly ITokenProvider AuthInfo; private DateTime _lastValidated; private (ValidateInfo info, ResponseMetadata header) _lastValidatedInfo; - private readonly AsyncLock _authLock = new(); - private readonly AsyncLock _authValidationLock = new(); + private AsyncLock _authLock = new(); public NexusApi(ITokenProvider authInfo, ILogger logger, HttpClient client, IResource limiter, ApplicationInfo appInfo, JsonSerializerOptions jsonOptions) @@ -54,14 +53,12 @@ public NexusApi(ITokenProvider authInfo, ILogger logg { var (isApi, code) = await GetAuthInfo(); - using var _ = await _authValidationLock.WaitAsync(); - if (isApi) { var msg = await GenerateMessage(HttpMethod.Get, Endpoints.Validate); _lastValidatedInfo = await Send(msg, token); } - else if(_lastValidated < DateTime.Now - TimeSpan.FromMinutes(5)) // We don't want to spam the validate endpoint when starting a modlist download + else { var msg = await GenerateMessage(HttpMethod.Get, Endpoints.OAuthValidate); var (data, header) = await Send(msg, token); @@ -71,10 +68,9 @@ public NexusApi(ITokenProvider authInfo, ILogger logg Name = data.Name, }; _lastValidatedInfo = (validateInfo, header); - - _lastValidated = DateTime.Now; } + _lastValidated = DateTime.Now; return _lastValidatedInfo; }