diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 1b5bab5b..5b899582 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -491,14 +491,12 @@ namespace MP.Data.Controllers { //query = query.Where(x => x.Tipo.ToLower() == tipoArt.ToLower()); query = query.Where(x => EF.Functions.Like(x.Tipo, tipoArt)); - } // filtro azienda if (azienda != "*") { //query = query.Where(x => x.Azienda.ToLower() == azienda.ToLower()); query = query.Where(x => EF.Functions.Like(x.Azienda, azienda)); - } // filtro ricerca if (!string.IsNullOrWhiteSpace(searchVal)) @@ -520,7 +518,6 @@ namespace MP.Data.Controllers .ToListAsync(); } - /// /// Elenco tabella Articoli NON IMPIEGATI (da stored stp_ART_getUsed) Async /// @@ -1076,20 +1073,16 @@ namespace MP.Data.Controllers /// *=tutti, altrimenti solo selezionato /// numero massimo record da restituire /// - public List FluxLogGetLastFilt(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec) + public async Task> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec) { - List dbResult = new List(); - using (var dbCtx = new MoonPro_FluxContext(_configuration)) - { - dbResult = dbCtx - .DbSetFluxLog - .AsNoTracking() - .Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux)) - .OrderByDescending(x => x.dtEvento) - .Take(MaxRec) - .ToList(); - } - return dbResult; + using var dbCtx = new MoonPro_FluxContext(_configuration); + return await dbCtx + .DbSetFluxLog + .AsNoTracking() + .Where(x => (x.dtEvento >= DtMin && x.dtEvento <= DtMax) && (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodFlux == "*" || x.CodFlux == CodFlux)) + .OrderByDescending(x => x.dtEvento) + .Take(MaxRec) + .ToListAsync() ?? new(); } /// @@ -1629,7 +1622,7 @@ namespace MP.Data.Controllers .ToList(); } return dbResult; - } + } #endif /// @@ -1805,7 +1798,6 @@ namespace MP.Data.Controllers .Select(i => i.IdxMacchina) .Distinct() .ToListAsync() ?? new(); - } /// diff --git a/MP.IOC/Data/MpDataService.cs b/MP.IOC/Data/MpDataService.cs index 74af58a3..2237d76c 100644 --- a/MP.IOC/Data/MpDataService.cs +++ b/MP.IOC/Data/MpDataService.cs @@ -1541,7 +1541,7 @@ namespace MP.IOC.Data } else { - result = await Task.FromResult(SpecDbController.FluxLogGetLastFilt(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec)); + result = await SpecDbController.FluxLogGetLastFiltAsync(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); if (string.IsNullOrEmpty(canCacheParametri)) diff --git a/MP.SPEC/Components/ListPARAMS.razor.cs b/MP.SPEC/Components/ListPARAMS.razor.cs index 4e254b81..f65ba554 100644 --- a/MP.SPEC/Components/ListPARAMS.razor.cs +++ b/MP.SPEC/Components/ListPARAMS.razor.cs @@ -108,7 +108,7 @@ namespace MP.SPEC.Components dataTo = (DateTime)SelDtMax; } - SearchRecords = await MDService.FluxLogGetLastFilt(dataTo, dataFrom, SelMacchina, SelFlux, MaxRecord, RefreshPeriod / 1000); + SearchRecords = await MDService.FluxLogGetLastFiltAsync(dataTo, dataFrom, SelMacchina, SelFlux, MaxRecord, RefreshPeriod / 1000); totalCount = SearchRecords.Count; ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); await Task.Delay(1); diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 2928da0e..533b6855 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -571,7 +571,7 @@ namespace MP.SPEC.Data return await GetOrFetchAsync( operationName: "DossiersGetLastFiltAsync", cacheKey: currKey, - expiration: getRandTOut(redisLongTimeCache), + expiration: getRandTOut(redisLongTimeCache * 5), fetchFunc: async () => await dbController.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List(), tagList: [Utils.redisDossByMac] ); @@ -1055,50 +1055,26 @@ namespace MP.SPEC.Data } /// - /// Elenco ultimi n record flux log dato idxMaccSel e flusso (ordinato x data registrazione) + /// Elenco FluxLog in modalità filtro /// /// Data massima x eventi /// Data minima x eventi /// * = tutte, altrimenti solo x una data idxMaccSel /// *=tutti, altrimenti solo selezionato /// numero massimo record da restituire + /// durata cache in secondi /// - public async Task> FluxLogGetLastFilt(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec, double redisCacheSec) + public async Task> FluxLogGetLastFiltAsync(DateTime DtMax, DateTime DtMin, string IdxMacchina, string CodFlux, int MaxRec, double redisCacheSec) { - using var activity = ActivitySource.StartActivity("FluxLogGetLastFilt"); - List? result = new List(); - string source = "DB"; string currKey = $"{Utils.redisFluxLogFilt}:{IdxMacchina}:{CodFlux}:{MaxRec}:{DtMax:yyyyMMddHHmm}:{DtMin:yyyyMMddHHmm}"; - // cerco in redis dato valore sel idxMaccSel... - RedisValue rawData = redisDb.StringGet(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = await Task.FromResult(dbController.FluxLogGetLastFilt(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec)); - // serializzo e salvo... - rawData = JsonConvert.SerializeObject(result); - if (string.IsNullOrEmpty(canCacheParametri)) - { - canCacheParametri = await ConfigTryGetAsync("SPEC_ParametriEnableRedisCache"); - } - if (canCacheParametri != "false") - { - redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(redisCacheSec)); - } - } - if (result == null) - { - result = new List(); - } - activity?.SetTag("data.source", source); - activity?.SetTag("result.count", result.Count); - activity?.Stop(); - LogTrace($"FluxLogGetLastFilt | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); - return result; + + return await GetOrFetchAsync( + operationName: "FluxLogGetLastFiltAsync", + cacheKey: currKey, + expiration: TimeSpan.FromSeconds(redisCacheSec), + fetchFunc: async () => await dbController.FluxLogGetLastFiltAsync(DtMax, DtMin, IdxMacchina, CodFlux, MaxRec) ?? new List(), + tagList: [Utils.redisFluxLogFilt] + ); } /// diff --git a/Refactor_Plan.md b/Refactor_Plan.md index 0388a4d9..c4097387 100644 --- a/Refactor_Plan.md +++ b/Refactor_Plan.md @@ -32,6 +32,16 @@ I metodi verranno suddivisi in: - [x] `TemplateKitFiltAsync` - [x] `AnagTipoArtLvAsync` - [x] `ElencoLinkAsync` +- [x] `ConfigGetAllAsync` +- [x] `DossiersGetLastFiltAsync` +- [x] `ElencoGruppiFaseAsync` +- [x] `IstKitFiltAsync` +- [x] `ListGiacenzeAsync` +- [x] `MacchineWithFluxAsync` +- [x] `POdlListGetFiltAsync` +- [x] `TksScoreAsync` +- [x] `WipKitFiltAsync` +- [x] `POdlGetByOdlAsync` - [ ] `AnagEventiGeneral` - [ ] `AnagEventiGetByMacch` - [ ] `AnagKeyValGetAll` @@ -39,20 +49,14 @@ I metodi verranno suddivisi in: - [ ] `AnagTipoArtLvAsync` - [ ] `ArticleWithDossier` - [ ] `ConfigGetAll` -- [ ] `ConfigGetAllAsync` - [ ] `DbDedupStats` -- [ ] `DossiersGetLastFilt` -- [ ] `ElencoGruppiFase` - [ ] `ElencoRepartiDTO` - [ ] `ExpiryReloadParamGet` - [ ] `IobInfo` -- [ ] `IstKitFilt` -- [ ] `ListGiacenze` - [ ] `ListPODL_ByCodArt` - [ ] `MacchineGetFilt` - [ ] `MacchineRecipeArchive` - [ ] `MacchineRecipeConf` -- [ ] `MacchineWithFlux` - [ ] `MachIobConf` - [ ] `MseGetAll` - [ ] `OdlByBatch` @@ -61,17 +65,11 @@ I metodi verranno suddivisi in: - [ ] `OperatoriGetFilt` - [ ] `ParametriGetFilt` - [ ] `POdlGetByKey` -- [ ] `POdlGetByOdl` - [ ] `POdlListByKitParent` -- [ ] `POdlListGetFilt` -- [ ] `POdlListGetFiltAsync` - [ ] `ProcFLStats` - [ ] `StatoMacchina` - [ ] `TagConfGetKey` -- [ ] `TemplateKitFilt` -- [ ] `TksScore` - [ ] `VocabolarioGetAll` -- [ ] `WipKitFilt` #### Fase 3: Refactoring Metodi di Scrittura e Invalidazione - [ ] `AnagGruppiDelete`