diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 3a06287d..938a45e0 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -122,21 +122,17 @@ namespace MP.Data.Controllers /// Nome Table x filtro (std: EvList) /// Nome Field x filtro (std: Common) /// - public List AnagEventiGeneral(string TableName = "EvList", string FieldName = "Common") + public async Task> AnagEventiGeneralAsync(string TableName = "EvList", string FieldName = "Common") { - List dbResult = new List(); - using (var dbCtx = new MoonProContext(options)) - { - var pTableName = new SqlParameter("@TableName", TableName); - var pFieldName = new SqlParameter("@FieldName", FieldName); - dbResult = dbCtx - .DbSetVSEB - .FromSqlRaw("exec dbo.stp_vseb_getGenerallyAvailable @TableName, @FieldName", pTableName, pFieldName) - .AsNoTracking() - .AsEnumerable() - .ToList(); - } - return dbResult; + using var dbCtx = new MoonProContext(options); + var pTableName = new SqlParameter("@TableName", TableName); + var pFieldName = new SqlParameter("@FieldName", FieldName); + var dbResult = await dbCtx + .DbSetVSEB + .FromSqlRaw("exec dbo.stp_vseb_getGenerallyAvailable @TableName, @FieldName", pTableName, pFieldName) + .AsNoTracking() + .ToListAsync(); + return dbResult ?? new(); } /// diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 5bb2bfd7..21b88660 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -157,35 +157,25 @@ namespace MP.SPEC.Data /// Elenco EVENTI validi x ogni macchina secondo conf standard macchina /// /// - public List AnagEventiGeneral() + public async Task> AnagEventiGeneralAsync() { - using var activity = ActivitySource.StartActivity("AnagEventiGeneral"); - string source = "DB"; - List? result = new List(); - // cerco in redisConn... - string currKey = $"{Utils.redisEventList}:VSEB:GENERAL"; - RedisValue rawData = redisDb.StringGet(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = dbController.AnagEventiGeneral(); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache)); - } - if (result == null) - { - result = new List(); - } - activity?.SetTag("data.source", source); - activity?.SetTag("result.count", result.Count); - activity?.Stop(); - LogTrace($"AnagEventiGeneral | {source} | {activity?.Duration.TotalMilliseconds}ms"); - return result; + string redisKey = $"{Utils.redisEventList}:VSEB:GENERAL"; + + return await GetOrFetchAsync( + operationName: "AnagEventiGeneralAsync", + cacheKey: redisKey, + 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(); + } + ); } /// diff --git a/MP.SPEC/Pages/RepStop.razor.cs b/MP.SPEC/Pages/RepStop.razor.cs index 2bc4bd0c..20317090 100644 --- a/MP.SPEC/Pages/RepStop.razor.cs +++ b/MP.SPEC/Pages/RepStop.razor.cs @@ -212,7 +212,7 @@ namespace MP.SPEC.Pages private async Task ReloadData() { CurrMSE = await MDService.MseGetAll(false); - SearchFermate = MDService.AnagEventiGeneral(); + SearchFermate = await MDService.AnagEventiGeneralAsync(); } #endregion Private Methods