diff --git a/MP.SPEC/Components/ListPODL.razor.cs b/MP.SPEC/Components/ListPODL.razor.cs index 44897fbc..b131fcac 100644 --- a/MP.SPEC/Components/ListPODL.razor.cs +++ b/MP.SPEC/Components/ListPODL.razor.cs @@ -171,11 +171,22 @@ namespace MP.SPEC.Components await ReloadBaseData(); } + private string? _lastPadCodXdl; + private bool _initialized; + protected override async Task OnParametersSetAsync() { - if (!lastFilter.Equals(actFilter)) + // esempio: verifica parametri minimi + if (string.IsNullOrEmpty(padCodXdl) || actFilter == null) + return; + + if (!_initialized || !lastFilter.Equals(actFilter) || _lastPadCodXdl != padCodXdl) { + _initialized = true; + lastFilter = actFilter.clone(); + _lastPadCodXdl = padCodXdl; + await ReloadData(); } } @@ -243,6 +254,41 @@ namespace MP.SPEC.Components } } + protected async Task ReloadData() + { + isLoading = true; + ListRecords = null; + + // ✅ lancia in parallelo + var odlTask = UpdateOdlList(); + + Task> searchTask; + + if (actFilter.ShowKit) + { + searchTask = MDService.POdlListGetFiltAsync(hasOdl, StatoSel, macchina, reparto, selDtStart, selDtEnd); + } + else + { + searchTask = MDService.POdlToKitListGetFiltAsync(hasOdl, StatoSel, macchina, reparto, selDtStart, selDtEnd); + } + + // ✅ aspetta tutto insieme + await Task.WhenAll(odlTask, searchTask); + + SearchRecords = searchTask.Result; + + totalCount = SearchRecords.Count; + + ListRecords = SearchRecords + .Skip(numRecord * (currPage - 1)) + .Take(numRecord) + .ToList(); + + isLoading = false; + } + +#if false protected async Task ReloadData() { ListRecords = null; @@ -262,9 +308,9 @@ namespace MP.SPEC.Components totalCount = SearchRecords.Count; } ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); - //await InvokeAsync(() => StateHasChanged()); isLoading = false; - } + } +#endif protected async Task resetSel(bool forceUpdate) { diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 79499830..4014b17d 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -1804,6 +1804,25 @@ 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 GetOrCreateCachedAsync( + operationName: "MacchineGetFiltAsync", + memKey: memKey, + redisKey: redisKey, + // ✅ TTL coerente con il tuo requisito (prima avevi 1 minuto) + memoryTtl: TimeSpan.FromMinutes(1), + dbFactory: async () => + await dbController.MacchineGetFiltAsync(codGruppo) + ?? new List() + ); + } +#if false public async Task> MacchineGetFiltAsync(string codGruppo) { using var activity = ActivitySource.StartActivity("MacchineGetFiltAsync"); @@ -1853,7 +1872,8 @@ namespace MP.SPEC.Data LogTrace($"MacchineGetFiltAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); return result; - } + } +#endif /// /// Verifica se la idxMaccSel abbia un codice PATH ricette associato