From f38b85ce3980946460eb58ad2cac5d0ccceef7dc Mon Sep 17 00:00:00 2001 From: Charlotte Date: Thu, 6 Feb 2025 19:00:20 +0100 Subject: [PATCH] fix static file server statistics resetting (#33) Currently, the static file server will try to reset the statistics about files served rapidly starting from midnight for about a second. This removes log spam and a load spike at midnight. --- .../Services/FileStatisticsService.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/FileStatisticsService.cs b/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/FileStatisticsService.cs index 3d25ecb..cc6c0f0 100644 --- a/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/FileStatisticsService.cs +++ b/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/FileStatisticsService.cs @@ -77,10 +77,9 @@ public class FileStatisticsService : IHostedService _metrics.SetGaugeTo(MetricsAPI.GaugeFilesUniquePastDay, 0); _metrics.SetGaugeTo(MetricsAPI.GaugeFilesUniquePastDaySize, 0); - var now = DateTime.UtcNow; - TimeOnly currentTime = new(now.Hour, now.Minute, now.Second); - TimeOnly futureTime = new(0, 0, 0); - var span = futureTime - currentTime; + var now = DateTime.UtcNow; + DateTime midnight = new(now.Date, new(0, 0, 0)); + var span = midnight.AddDays(1) - now; await Task.Delay(span, _resetCancellationTokenSource.Token).ConfigureAwait(false); }