From 679008895066a99efb3e39b5e3938f896c5b5697 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 15 Sep 2022 13:09:05 +0200 Subject: [PATCH] Ancora update x gestione filtro/stop live... --- MP.SPEC/Components/ListPARAMS.razor.cs | 17 +++++++++++------ MP.SPEC/Data/MpDataService.cs | 21 ++++++++++++++------- MP.SPEC/Pages/PARAMS.razor.cs | 5 ++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/MP.SPEC/Components/ListPARAMS.razor.cs b/MP.SPEC/Components/ListPARAMS.razor.cs index 22bb17dd..61a4548e 100644 --- a/MP.SPEC/Components/ListPARAMS.razor.cs +++ b/MP.SPEC/Components/ListPARAMS.razor.cs @@ -15,7 +15,17 @@ namespace MP.SPEC.Components public EventCallback TotRecordChanged { get; set; } [Parameter] - public bool LiveUpdate { get; set; } + public bool LiveUpdate + { + get => _liveUpdate; + set + { + _liveUpdate = value; + // var pUpd = Task.Run(async () => await reloadData(false)); + // pUpd.Wait(); + } + } + private bool _liveUpdate { get; set; } [Parameter] @@ -225,14 +235,9 @@ namespace MP.SPEC.Components if (_totalCount != value) { _totalCount = value; - - //var pUpd = Task.Run(async () => await TotRecordChanged.InvokeAsync(value)); - //pUpd.Wait(); TotRecordChanged.InvokeAsync(value); } } - //get => MessageService.totalCount; - //set => MessageService.totalCount = value; } #endregion Private Properties diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 080ca3ac..416d4ebd 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -283,6 +283,7 @@ namespace MP.SPEC.Data { // Clear database controller dbController.Dispose(); + redisConn.Dispose(); } /// @@ -442,14 +443,20 @@ namespace MP.SPEC.Data public async Task> ParametriGetFilt(string IdxMacchina) { List? result = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string readType = "DB"; + result = await Task.FromResult(dbController.ParametriGetFilt(IdxMacchina)); + + #if false // 2 minuti valore cache int maxAgeMin = 5; - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); + string currKey = $"{redisFluxByMac}:{IdxMacchina}"; + // cerco in redis dato valore sel macchina... - RedisValue rawData = await redisDb.StringGetAsync($"{redisFluxByMac}:{IdxMacchina}"); + RedisValue rawData = await redisDb.StringGetAsync(currKey); if (!string.IsNullOrEmpty($"{rawData}")) { result = JsonConvert.DeserializeObject>($"{rawData}"); @@ -462,16 +469,16 @@ namespace MP.SPEC.Data result = await Task.FromResult(dbController.ParametriGetFilt(IdxMacchina)); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync($"{redisFluxByMac}:{IdxMacchina}", rawData, TimeSpan.FromMinutes(maxAgeMin)); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Debug($"ParametriGetFilt | Read from DB: {ts.TotalMilliseconds}ms"); + await redisDb.StringSetAsync(currKey, rawData, TimeSpan.FromMinutes(maxAgeMin)); } if (result == null) { result = new List(); } #endif + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ParametriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms"); return result; } diff --git a/MP.SPEC/Pages/PARAMS.razor.cs b/MP.SPEC/Pages/PARAMS.razor.cs index fc55bb4a..204bba34 100644 --- a/MP.SPEC/Pages/PARAMS.razor.cs +++ b/MP.SPEC/Pages/PARAMS.razor.cs @@ -49,12 +49,13 @@ namespace MP.SPEC.Pages protected void ForceReloadPage(int newNum) { - liveUpdate = newNum == 1; + //liveUpdate = newNum == 1; currPage = newNum; } protected void updateTotal(int newTotCount) { + //await Task.Delay(1); totalCount = newTotCount; } @@ -137,6 +138,7 @@ namespace MP.SPEC.Pages _selFlux = value; ForceReloadPage(1); isLoading = false; + liveUpdate = false; } } } @@ -163,6 +165,7 @@ namespace MP.SPEC.Pages ForceReloadPage(1); isLoading = false; + liveUpdate = false; } } }