From d8bc1379be3f8a1bfc421a10d6c462363d97581d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 27 May 2026 19:12:57 +0200 Subject: [PATCH] Ancora update componenti con review tags --- MP.SPEC/Components/ListPODL.razor.cs | 6 +- MP.SPEC/Data/MpDataService.cs | 110 +++++++++++++++------------ MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 6 files changed, 67 insertions(+), 57 deletions(-) diff --git a/MP.SPEC/Components/ListPODL.razor.cs b/MP.SPEC/Components/ListPODL.razor.cs index b131fcac..e6ac8080 100644 --- a/MP.SPEC/Components/ListPODL.razor.cs +++ b/MP.SPEC/Components/ListPODL.razor.cs @@ -215,7 +215,7 @@ namespace MP.SPEC.Components ListRecords = null; isLoading = true; - var list = await MDService.OdlGetCurrentAsync(); + var list = await MDService.MachineWithOdlAsync(); _odlCurrSet = list.ToHashSet(); var machines = await MDService.MacchineGetFiltAsync("*"); @@ -610,7 +610,7 @@ namespace MP.SPEC.Components } /// - /// verifica se sia avviabile ODL x idxMaccSel + /// Verifica se sia avviabile ODL x idxMaccSel /// /// /// @@ -621,7 +621,7 @@ namespace MP.SPEC.Components private async Task UpdateOdlList() { - var list = await MDService.OdlGetCurrentAsync(); + var list = await MDService.MachineWithOdlAsync(); _odlCurrSet = list.ToHashSet(); } diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 21b88660..eb470669 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -159,22 +159,15 @@ namespace MP.SPEC.Data /// public async Task> AnagEventiGeneralAsync() { - string redisKey = $"{Utils.redisEventList}:VSEB:GENERAL"; - return await GetOrFetchAsync( operationName: "AnagEventiGeneralAsync", - cacheKey: redisKey, + cacheKey: $"{Utils.redisEventList}:VSEB:GENERAL", expiration: getRandTOut(redisLongTimeCache), fetchFunc: async () => { - RedisValue rawData = await redisDb.StringGetAsync(redisKey); - if (rawData.HasValue) - { - return JsonConvert.DeserializeObject>($"{rawData}") ?? new List(); - } - return await dbController.AnagEventiGeneralAsync() ?? new List(); - } + }, + tagList: [Utils.redisEventList] ); } @@ -292,7 +285,8 @@ namespace MP.SPEC.Data cacheKey: Utils.redisStatoCom, expiration: TimeSpan.FromMinutes(redisLongTimeCache), fetchFunc: async () => - await dbController.AnagStatiCommAsync() ?? new List() + await dbController.AnagStatiCommAsync() ?? new List(), + tagList: [Utils.redisStatoCom] ); } @@ -395,8 +389,8 @@ namespace MP.SPEC.Data cacheKey: redisKey, expiration: TimeSpan.FromMinutes(2), fetchFunc: async () => - await dbController.ArticoliGetByTipoAsync(tipo, azienda) - ?? new List() + await dbController.ArticoliGetByTipoAsync(tipo, azienda) ?? new List(), + tagList: [Utils.redisArtList, $"{Utils.redisArtList}:Tipo"] ); } @@ -417,8 +411,8 @@ namespace MP.SPEC.Data cacheKey: redisKey, expiration: TimeSpan.FromMinutes(redisLongTimeCache), fetchFunc: async () => - await dbController.ArticoliGetSearchAsync(numRecord, tipoArt, azienda, searchVal) - ?? new List() + await dbController.ArticoliGetSearchAsync(numRecord, tipoArt, azienda, searchVal) ?? new List(), + tagList: [Utils.redisArtList, $"{Utils.redisArtList}:Search"] ); } @@ -480,7 +474,7 @@ namespace MP.SPEC.Data activity?.SetTag("data.source", source); activity?.Stop(); - LogTrace($"ArticoloDelEnabled | Cod: {codArticolo} | Source: {source}"); + LogTrace($"ArticoloDelEnabled | Cod: {codArticolo} | {source} | {activity?.Duration.TotalMilliseconds}ms"); return !usato; } @@ -796,7 +790,8 @@ namespace MP.SPEC.Data cacheKey: $"{Utils.redisAnagGruppi}:Aziende", expiration: TimeSpan.FromMinutes(redisLongTimeCache * 2), fetchFunc: async () => - await dbController.AnagGruppiAziendeAsync() ?? new List() + await dbController.AnagGruppiAziendeAsync() ?? new List(), + tagList: [Utils.redisAnagGruppi, $"{Utils.redisAnagGruppi}:Aziende"] ); } @@ -1086,11 +1081,9 @@ namespace MP.SPEC.Data /// public async Task FlushCacheAsync() { - bool fatto = false; - await _cache.ClearAsync(); + await _cache.ClearAsync(allowFailSafe: false); _configData.Clear(); - fatto = true; - return fatto; + return true; } /// @@ -1099,11 +1092,11 @@ namespace MP.SPEC.Data /// public async Task FlushCacheByTagAsync(string tag) { - bool fatto = false; + if (string.IsNullOrWhiteSpace(tag)) return false; + await _cache.RemoveByTagAsync(tag); _configData.Clear(); - fatto = true; - return fatto; + return true; } /// @@ -1112,14 +1105,17 @@ namespace MP.SPEC.Data /// public async Task FlushCacheByTagsAsync(List listTags) { - bool fatto = false; - foreach (var item in listTags) - { - await _cache.RemoveByTagAsync(item); - } + if (listTags == null || listTags.Count == 0) return false; + + // Generiamo i Task di rimozione ed eseguiamoli in parallelo su Redis/L1 + var tasks = listTags + .Where(tag => !string.IsNullOrWhiteSpace(tag)) + .Select(tag => _cache.RemoveByTagAsync(tag).AsTask()); + + await Task.WhenAll(tasks); + _configData.Clear(); - fatto = true; - return fatto; + return true; } public async Task FlushCacheFluxLog() @@ -1681,9 +1677,7 @@ namespace MP.SPEC.Data public async Task> MacchineGetFiltAsync(string codGruppo) { string keyGrp = codGruppo != "*" ? codGruppo : "ALL"; - string redisKey = $"{Utils.redisMacList}:{keyGrp}"; - string memKey = $"MACCHINE_MEM:{keyGrp}"; return await GetOrFetchAsync( operationName: "MacchineGetFiltAsync", @@ -1691,7 +1685,8 @@ namespace MP.SPEC.Data expiration: TimeSpan.FromMinutes(5), fetchFunc: async () => await dbController.MacchineGetFiltAsync(codGruppo) - ?? new List() + ?? new List(), + tagList: [Utils.redisMacList] ); } @@ -2005,13 +2000,12 @@ namespace MP.SPEC.Data return dbResult; } - public async Task> OdlGetCurrentAsync() + public async Task> MachineWithOdlAsync() { string redisKey = Utils.redisOdlCurrByMac; - string memKey = $"MEM:{redisKey}"; return await GetOrFetchAsync( - operationName: "OdlGetCurrentAsync", + operationName: "MachineWithOdlAsync", cacheKey: redisKey, expiration: TimeSpan.FromSeconds(3), fetchFunc: async () => @@ -2023,7 +2017,8 @@ namespace MP.SPEC.Data .ToList(); return dbResult ?? new List(); - } + }, + tagList: [Utils.redisOdlCurrByMac] ); } @@ -2448,7 +2443,7 @@ namespace MP.SPEC.Data return await GetOrFetchAsync( operationName: "POdlToKitListGetFiltAsync", cacheKey: redisKey, - expiration: TimeSpan.FromSeconds(redisShortTimeCache), + expiration: TimeSpan.FromSeconds(redisShortTimeCache * 5), fetchFunc: async () => await dbController.ListPODL_KitFiltAsync( lanciato, @@ -2457,7 +2452,8 @@ namespace MP.SPEC.Data codGruppo, startDate, endDate - ) ?? new List() + ) ?? new List(), + tagList: [Utils.redisPOdlList, $"{Utils.redisPOdlList}_kit"] ); } @@ -3273,7 +3269,7 @@ namespace MP.SPEC.Data /// /// /// - private async Task GetOrFetchAsync(string operationName, string cacheKey, Func> fetchFunc, TimeSpan expiration, params string[] tags) + private async Task GetOrFetchAsync(string operationName, string cacheKey, Func> fetchFunc, TimeSpan expiration, params string[] tagList) { using var activity = ActivitySource.StartActivity(operationName); string source; @@ -3289,6 +3285,13 @@ namespace MP.SPEC.Data return result; } bool fromDb = false; + // cache in redis + var cacheOptions = new FusionCacheEntryOptions() + .SetDuration(expiration) + .SetFailSafe(true); + // cache in RAM per 1/3 del tempo x risparmiare risorse + cacheOptions.MemoryCacheDuration = expiration / 3; + var final = await _cache.GetOrSetAsync( cacheKey, async _ => @@ -3296,19 +3299,26 @@ namespace MP.SPEC.Data fromDb = true; return await fetchFunc(); }, - opt => - { - opt.SetDuration(expiration) - .SetFailSafe(true); - - //if (tags != null && tags.Length > 0) - // opt.SetTags(tags); - }); + options: cacheOptions, + tags: tagList + ); source = fromDb ? "DB" : "REDIS"; activity?.SetTag("data.source", source); activity?.Stop(); - LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms"); + // switch log in base a source.. + switch (source) + { + case "DB": + LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Info); + break; + case "REDIS": + LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms", reqLevel: NLog.LogLevel.Debug); + break; + default: + LogTrace($"{operationName} | {source} | {activity?.Duration.TotalMilliseconds:F4} ms"); + break; + } return final!; } diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index d1b23d66..639786b0 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2605.2716 + 8.16.2605.2719 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 6f105936..3f685ead 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 8.16.2605.2716

+

Versione: 8.16.2605.2719


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 9a3dbb19..a3677dd7 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2605.2716 +8.16.2605.2719 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 003046c0..2bef6128 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2605.2716 + 8.16.2605.2719 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false