Code Optimizations for SignalR/ApiController

This commit is contained in:
BoxuChan
2025-09-05 17:47:02 +02:00
parent f0cef81b5e
commit 6e9c69c2a8

View File

@@ -310,7 +310,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
_ = Task.Run(async () => await StopConnection(ServerState.Disconnected).ConfigureAwait(false)); _ = Task.Run(async () => await StopConnection(ServerState.Disconnected).ConfigureAwait(false));
_connectionCancellationTokenSource?.Cancel(); _connectionCancellationTokenSource?.Cancel();
} }
private int _unhealthy = 0;
private async Task ClientHealthCheck(CancellationToken ct) private async Task ClientHealthCheck(CancellationToken ct)
{ {
while (!ct.IsCancellationRequested && _mareHub != null) while (!ct.IsCancellationRequested && _mareHub != null)
@@ -318,17 +318,11 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
await Task.Delay(TimeSpan.FromSeconds(30), ct).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(30), ct).ConfigureAwait(false);
var healthy = await CheckClientHealth().ConfigureAwait(false); var healthy = await CheckClientHealth().ConfigureAwait(false);
if (!healthy || _mareHub.State != HubConnectionState.Connected) if (!healthy || _mareHub.State != HubConnectionState.Connected)
{
_unhealthy++;
if (_unhealthy > 0)
{ {
Logger.LogWarning("Health check failed, forcing reconnect. ClientHealth: {0} HubConnected: {1}", healthy, _mareHub.State != HubConnectionState.Connected); Logger.LogWarning("Health check failed, forcing reconnect. ClientHealth: {0} HubConnected: {1}", healthy, _mareHub.State != HubConnectionState.Connected);
await ForceResetConnection().ConfigureAwait(false); await ForceResetConnection().ConfigureAwait(false);
_unhealthy = 0;
} }
} }
else _unhealthy = 0;
}
} }
private void DalamudUtilOnLogIn() private void DalamudUtilOnLogIn()