diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index a54e488d..3c49b185 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -1377,32 +1377,19 @@ namespace MP.SPEC.Data /// public async Task MacchineRecipeArchiveAsync(string idxMacchina) { - using var activity = ActivitySource.StartActivity("MacchineRecipeArchiveAsync"); - string? result = ""; - string source = "DB"; string currKey = $"{Utils.redisMacRecipePath}:{idxMacchina}"; - // cerco in redis dato valore sel idxMaccSel... - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject($"{rawData}"); - source = "REDIS"; - } - else - { - //recupero elenco macchine... - var machineList = await MacchineGetFiltAsync("*"); - var currMach = machineList.Where(x => x.IdxMacchina == idxMacchina).FirstOrDefault(); - result = currMach != null ? currMach.RecipeArchivePath : null; - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); - } - activity?.SetTag("data.source", source); - activity?.SetTag("result.count", 1); - activity?.Stop(); - LogTrace($"MacchineRecipeArchiveAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); - return result ?? ""; + return await GetOrFetchAsync( + operationName: "MacchineRecipeArchiveAsync", + cacheKey: currKey, + expiration: getRandTOut(redisLongTimeCache), + fetchFunc: async () => + { + var machineList = await MacchineGetFiltAsync("*"); + var currMach = machineList.FirstOrDefault(x => x.IdxMacchina == idxMacchina); + return currMach?.RecipeArchivePath ?? ""; + }, + tagList: [Utils.redisMacRecipePath] + ); } /// @@ -1412,34 +1399,39 @@ namespace MP.SPEC.Data /// public async Task MacchineRecipeConfAsync(string idxMacchina) { - using var activity = ActivitySource.StartActivity("MacchineRecipeConfAsync"); - string? result = ""; - string source = "DB"; string currKey = $"{Utils.redisMacRecipeConf}:{idxMacchina}"; - // cerco in redis dato valore sel idxMaccSel... - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject($"{rawData}"); - source = "REDIS"; - } - else - { - //recupero elenco macchine... - var machineList = await MacchineGetFiltAsync("*"); - var currMach = machineList.Where(x => x.IdxMacchina == idxMacchina).FirstOrDefault(); - result = currMach != null ? currMach.RecipePath : null; - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); - } - activity?.SetTag("data.source", source); - activity?.SetTag("result.count", 1); - activity?.Stop(); - LogTrace($"MacchineRecipeConfAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); - return result ?? ""; + return await GetOrFetchAsync( + operationName: "MacchineRecipeConfAsync", + cacheKey: currKey, + expiration: getRandTOut(redisLongTimeCache), + fetchFunc: async () => + { + var machineList = await MacchineGetFiltAsync("*"); + var currMach = machineList.FirstOrDefault(x => x.IdxMacchina == idxMacchina); + return currMach?.RecipePath ?? ""; + }, + tagList: [Utils.redisMacRecipeConf] + ); } + /// + /// Elenco operatori filtrati x gruppo + /// + /// + /// + public async Task> OperatoriGetFiltAsync(string codGruppo) + { + string keyGrp = codGruppo != "*" ? codGruppo : "ALL"; + string currKey = $"{Utils.redisOprList}:{keyGrp}"; + + return await GetOrFetchAsync( + operationName: "OperatoriGetFiltAsync", + cacheKey: currKey, + expiration: getRandTOut(redisLongTimeCache), + fetchFunc: async () => await dbController.OperatoriGetFiltAsync(codGruppo) ?? new List(), + tagList: [Utils.redisOprList] + ); + } /// /// Elenco id Macchine che abbiano dati FLuxLog, nel periodo indicato /// @@ -1725,42 +1717,6 @@ namespace MP.SPEC.Data return result; } - /// - /// Elenco operatori filtrati x gruppo - /// - /// - /// - public async Task> OperatoriGetFiltAsync(string codGruppo) - { - using var activity = ActivitySource.StartActivity("OperatoriGetFiltAsync"); - List? result = new List(); - string source = "DB"; - string keyGrp = codGruppo != "*" ? codGruppo : "ALL"; - string currKey = $"{Utils.redisOprList}:{keyGrp}"; - // cerco in redis dato valore sel idxMaccSel... - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = await dbController.OperatoriGetFiltAsync(codGruppo); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache)); - } - if (result == null) - { - result = new List(); - } - activity?.SetTag("result.count", result.Count); - activity?.Stop(); - LogTrace($"OperatoriGetFiltAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); activity?.SetTag("data.source", source); - return result; - } - /// /// Elenco di tutti i parametri filtrati x idxMaccSel /// diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index c2064311..89bc4b9e 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 8.16.2605.2813 + 8.16.2605.2814 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 27cc5bf1..4a3ba3b7 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 8.16.2605.2813

+

Versione: 8.16.2605.2814


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 44370d54..6454cfbd 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -8.16.2605.2813 +8.16.2605.2814 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index bc74aaa7..8c6b95c1 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 8.16.2605.2813 + 8.16.2605.2814 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