From 690f7e636af92dec542d735a8473f4d368d7fff0 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Sat, 7 Feb 2026 19:28:30 +0100 Subject: [PATCH] Ottimizzazione RAM, UI e sistema di timing aste MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ridotto consumo RAM: limiti log, pulizia e compattazione dati aste, timer periodico di cleanup - UI piΓΉ fluida: cache locale aste, throttling aggiornamenti, refresh log solo se necessario - Nuovo sistema Ticker Loop: timing configurabile, strategie solo vicino alla scadenza, feedback puntate tardive - Migliorato layout e splitter, log visivo, gestione cache HTML - Aggiornata UI impostazioni e fix vari per performance e thread-safety --- Mimante/Models/AuctionInfo.cs | 109 ++- Mimante/Pages/Index.razor | 51 +- Mimante/Pages/Index.razor.cs | 207 +++++- Mimante/Pages/Settings.razor | 36 +- Mimante/Program.cs | 44 ++ Mimante/Services/ApplicationStateService.cs | 111 +++- Mimante/Services/AuctionMonitor.cs | 692 +++++++++++--------- Mimante/Services/HtmlCacheService.cs | 25 +- Mimante/Utilities/SettingsManager.cs | 27 + Mimante/wwwroot/css/modern-pages.css | 162 ++++- 10 files changed, 1068 insertions(+), 396 deletions(-) diff --git a/Mimante/Models/AuctionInfo.cs b/Mimante/Models/AuctionInfo.cs index 038973c..6f16573 100644 --- a/Mimante/Models/AuctionInfo.cs +++ b/Mimante/Models/AuctionInfo.cs @@ -13,8 +13,9 @@ namespace AutoBidder.Models { /// /// Numero massimo di righe di log da mantenere per ogni asta + /// Ridotto per ottimizzare consumo RAM /// - private const int MAX_LOG_LINES = 500; + private const int MAX_LOG_LINES = 200; public string AuctionId { get; set; } = ""; public string Name { get; set; } = ""; // Opzionale, puς essere lasciato vuoto @@ -176,6 +177,11 @@ namespace AutoBidder.Models { var timestamp = DateTime.Now.ToString("HH:mm:ss.fff"); + // DEBUG: Print per verificare che i log vengano aggiunti + #if DEBUG + System.Diagnostics.Debug.WriteLine($"[AddLog] {AuctionId}: {message}"); + #endif + // ?? DEDUPLICAZIONE: Se l'ultimo messaggio θ uguale, incrementa contatore if (AuctionLog.Count > 0) { @@ -233,9 +239,9 @@ namespace AutoBidder.Models public List LatencyHistory { get; set; } = new(); /// - /// Numero massimo di latenze da memorizzare + /// Numero massimo di latenze da memorizzare (ridotto per RAM) /// - private const int MAX_LATENCY_HISTORY = 20; + private const int MAX_LATENCY_HISTORY = 10; /// /// Aggiunge una misurazione di latenza allo storico @@ -390,6 +396,103 @@ namespace AutoBidder.Models /// [JsonIgnore] public double DuelAdvantage { get; set; } = 0; + + // ??????????????????????????????????????????????????????????????????? + // GESTIONE MEMORIA + // ??????????????????????????????????????????????????????????????????? + + /// + /// Pulisce tutti i dati in memoria dell'asta per liberare RAM. + /// Chiamare prima di rimuovere l'asta dalla lista. + /// + public void ClearData() + { + // Pulisci liste storiche + BidHistory?.Clear(); + BidHistory = null!; + + RecentBids?.Clear(); + RecentBids = null!; + + AuctionLog?.Clear(); + AuctionLog = null!; + + BidderStats?.Clear(); + BidderStats = null!; + + LatencyHistory?.Clear(); + LatencyHistory = null!; + + AggressiveBidders?.Clear(); + AggressiveBidders = null!; + + // Pulisci oggetti complessi + LastState = null; + CalculatedValue = null; + DuelOpponent = null; + WinLimitDescription = null; + + // Reset flag + IsTrackedFromStart = false; + TrackingStartedAt = null; + DeadlineUtc = null; + LastDeadlineUpdateUtc = null; + } + + /// + /// Compatta i dati mantenendo solo le informazioni recenti. + /// Utile per ridurre la memoria senza eliminare completamente i dati. + /// + public void CompactData(int maxBidHistory = 50, int maxRecentBids = 30, int maxLogLines = 100) + { + // Compatta BidHistory + if (BidHistory != null && BidHistory.Count > maxBidHistory) + { + var recent = BidHistory.TakeLast(maxBidHistory).ToList(); + BidHistory.Clear(); + BidHistory.AddRange(recent); + BidHistory.TrimExcess(); + } + + // Compatta RecentBids + if (RecentBids != null && RecentBids.Count > maxRecentBids) + { + var recent = RecentBids.TakeLast(maxRecentBids).ToList(); + RecentBids.Clear(); + RecentBids.AddRange(recent); + RecentBids.TrimExcess(); + } + + // Compatta AuctionLog + if (AuctionLog != null && AuctionLog.Count > maxLogLines) + { + var recent = AuctionLog.TakeLast(maxLogLines).ToList(); + AuctionLog.Clear(); + AuctionLog.AddRange(recent); + AuctionLog.TrimExcess(); + } + + // Compatta LatencyHistory + if (LatencyHistory != null && LatencyHistory.Count > 10) + { + var recent = LatencyHistory.TakeLast(10).ToList(); + LatencyHistory.Clear(); + LatencyHistory.AddRange(recent); + LatencyHistory.TrimExcess(); + } + + // Compatta BidderStats - mantieni solo i top bidders + if (BidderStats != null && BidderStats.Count > 20) + { + var topBidders = BidderStats + .OrderByDescending(kv => kv.Value.BidCount) + .Take(20) + .ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase); + BidderStats.Clear(); + foreach (var kv in topBidders) + BidderStats[kv.Key] = kv.Value; + } + } } /// diff --git a/Mimante/Pages/Index.razor b/Mimante/Pages/Index.razor index 86f6494..a81ca3d 100644 --- a/Mimante/Pages/Index.razor +++ b/Mimante/Pages/Index.razor @@ -27,7 +27,7 @@
- @auctions.Count + @(auctions?.Count ?? 0)
@@ -76,7 +76,7 @@
-
@@ -91,7 +91,7 @@
Aste Monitorate
- @if (auctions.Count == 0) + @if ((auctions?.Count ?? 0) == 0) {
Nessuna asta monitorata. Clicca su per iniziare. @@ -521,7 +521,7 @@
} -@* Script Splitter *@ +@* Script Splitter - Versione Fixed senza sovrapposizioni *@