Fix e pulizia metodi ODL

This commit is contained in:
Samuele Locatelli
2026-05-29 09:00:36 +02:00
parent 582004c605
commit 823af36971
44 changed files with 116 additions and 192 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP_TAB3</RootNamespace>
</PropertyGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MAPOSPEC </i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/MP-TAB3.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1
View File
@@ -43,6 +43,7 @@ namespace MP.Core
public const string redisMacRecipePath = redisBaseAddr + "Cache:RecipePath";
public const string redisOdlByBatch = redisXdlData + "OdlByBatch";
public const string redisOdlByKey = redisXdlData + "OdlByKey";
public const string redisOdlCurrByMac = redisXdlData + "OdlByMac";
public const string redisOdlLastByMac = redisXdlData + "LastOdlByMac";
+37 -29
View File
@@ -1875,22 +1875,23 @@ namespace MP.Data.Controllers
/// Elenco da tabella MappaStatoExplModel
/// </summary>
/// <returns></returns>
public List<MappaStatoExplModel> MseGetAll(int maxAge = 2000)
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
{
List<MappaStatoExplModel> dbResult = new List<MappaStatoExplModel>();
using (var dbCtx = new MoonProContext(options))
{
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
using var dbCtx = new MoonProContext(options);
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
dbResult = await dbCtx
.DbSetMSE
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
.AsNoTracking()
.ToListAsync();
dbResult = dbCtx
.DbSetMSE
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
.AsNoTracking()
.ToList();
}
return dbResult;
}
#if false
/// <summary>
/// Elenco ODL dato batch selezionato
/// </summary>
@@ -1916,31 +1917,36 @@ namespace MP.Data.Controllers
}
}
return dbResult;
}
#endif
/// <summary>
/// Elenco ODL dato batch selezionato
/// </summary>
/// <param name="BatchSel">Batch richiesto</param>
/// <returns></returns>
public async Task<List<int>> OdlByBatchAsync(string batchSel)
{
using var dbCtx = new MoonPro_InveContext(_configuration);
return await dbCtx
.DbGiacenzeData
.AsNoTracking()
.Where(x => x.IdentRG == batchSel)
.Select(x => x.IdxOdl)
.ToListAsync();
}
/// <summary>
/// ODL da chiave
/// </summary>
/// <returns></returns>
public ODLExpModel OdlByKey(int IdxOdl)
public async Task<ODLExpModel> OdlByKeyAsync(int IdxOdl)
{
ODLExpModel dbResult = new ODLExpModel();
using (var dbCtx = new MoonProContext(options))
{
try
{
dbResult = dbCtx
.DbSetODLExp
.AsNoTracking()
.Where(x => x.IdxOdl == IdxOdl)
.FirstOrDefault();
}
catch (Exception exc)
{
Log.Error($"Eccezione durante OdlByKey{Environment.NewLine}{exc}");
}
}
return dbResult;
using var dbCtx = new MoonProContext(options);
return await dbCtx
.DbSetODLExp
.AsNoTracking()
.FirstOrDefaultAsync(x => x.IdxOdl == IdxOdl);
}
/// <summary>
@@ -2025,6 +2031,7 @@ namespace MP.Data.Controllers
return fatto;
}
#if false
/// <summary>
/// Recupero odl data chiave
/// </summary>
@@ -2041,7 +2048,8 @@ namespace MP.Data.Controllers
.FirstOrDefaultAsync(x => x.IdxOdl == idxOdl);
}
return dbResult;
}
}
#endif
/// <summary>
/// Recupero Odl CORRENTI
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP.INVE</RootNamespace>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MAPOINVE </i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/MP.INVE.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-INVE/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MP-IOC </i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/MP.IOC.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-IOC/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>MP.Land</RootNamespace>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
<Configurations>Debug;Release;Debug_LiManDebug</Configurations>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<RunAnalyzersDuringBuild>True</RunAnalyzersDuringBuild>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo Tablet MAPO - DotNet6</i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/MP.Land.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-LAND/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP.MON</RootNamespace>
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MAPOSPEC </i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/MP.MON.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-MON/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>MP.Prog</RootNamespace>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo gestione Programmi MAPO</i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Prog.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP.RIOC</RootNamespace>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MP-RIOC </i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/MP.RIOC.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -18,7 +18,7 @@ namespace MP.SPEC.Components
{
if (!string.IsNullOrEmpty(BatchSel))
{
elencoODL = await MDService.OdlByBatch(BatchSel);
elencoODL = await MDService.OdlByBatchAsync(BatchSel);
}
else
{
+4 -2
View File
@@ -351,7 +351,8 @@ namespace MP.SPEC.Components
if (fatto)
{
var currPOdl = await MDService.POdlGetByKey(selRec.IdxPromessa);
var newOdl = await MDService.OdlGetByKey(currPOdl.IdxOdl);
var newOdl = await MDService.OdlByKeyAsync(currPOdl.IdxOdl);
//var newOdl = await MDService.OdlGetByKey(currPOdl.IdxOdl);
// registro evento...
idxEvento = 2;
@@ -658,7 +659,8 @@ namespace MP.SPEC.Components
// se manca codart calcolo...
if (string.IsNullOrEmpty(codArticolo))
{
var currOdl = await MDService.OdlGetByKey(idxODL);
var currOdl = await MDService.OdlByKeyAsync(idxODL);
//var currOdl = await MDService.OdlGetByKey(idxODL);
if (currOdl != null)
{
codArticolo = currOdl.CodArticolo;
+31 -64
View File
@@ -1431,7 +1431,6 @@ namespace MP.SPEC.Data
public async Task<Dictionary<string, string>> MachIobConfAsync(string IdxMacchina)
{
string redisKey = Utils.redisIobConf;
return await GetOrFetchAsync(
operationName: "MachIobConfAsync",
cacheKey: redisKey,
@@ -1455,36 +1454,22 @@ namespace MP.SPEC.Data
/// <summary>
/// Elenco MSE stato amcchine
/// </summary>
/// <param name="forceDb"></param>
/// <param name="forceDb">Force refresh from DB</param>
/// <returns></returns>
public async Task<List<MappaStatoExplModel>> MseGetAll(bool forceDb = false)
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(bool forceDb = false)
{
using var activity = ActivitySource.StartActivity("MseGetAllAsync");
string source = "DB";
List<MappaStatoExplModel>? result = new List<MappaStatoExplModel>();
// cerco in redisConn...
RedisValue rawData = redisDb.StringGet(Constants.redisMseKey);
if (rawData.HasValue && !forceDb)
if (forceDb)
{
result = JsonConvert.DeserializeObject<List<MappaStatoExplModel>>($"{rawData}");
source = "REDIS";
await _cache.RemoveAsync(Constants.redisMseKey);
}
else
{
result = await Task.FromResult(dbController.MseGetAll(2000));
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
await redisDb.StringSetAsync(Constants.redisMseKey, rawData, TimeSpan.FromSeconds(1));
}
if (result == null)
{
result = new List<MappaStatoExplModel>();
}
activity?.SetTag("data.source", source);
activity?.SetTag("result.count", result.Count);
activity?.Stop();
LogTrace($"MseGetAllAsync | {source} | {activity?.Duration.TotalMilliseconds}ms");
return result;
return await GetOrFetchAsync(
operationName: "MseGetAllAsync",
cacheKey: Constants.redisMseKey,
expiration: TimeSpan.FromSeconds(1),
fetchFunc: async () => await dbController.MseGetAllAsync(2000) ?? new(),
tagList: [Constants.redisMseKey]
);
}
/// <summary>
@@ -1506,35 +1491,15 @@ namespace MP.SPEC.Data
/// </summary>
/// <param name="BatchSel">Batch richiesto</param>
/// <returns></returns>
public async Task<List<int>> OdlByBatch(string BatchSel)
public async Task<List<int>> OdlByBatchAsync(string BatchSel)
{
using var activity = ActivitySource.StartActivity("OdlByBatch");
List<int>? result = new List<int>();
string source = "DB";
string currKey = Utils.redisOdlByBatch;
// cerco in redis dato valore sel idxMaccSel...
RedisValue rawData = redisDb.StringGet(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<int>>($"{rawData}");
source = "REDIS";
}
else
{
result = await Task.FromResult(dbController.OdlByBatch(BatchSel));
// serializzo e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, getRandTOut(redisLongTimeCache));
}
if (result == null)
{
result = new List<int>();
}
activity?.SetTag("data.source", source);
activity?.SetTag("result.count", result.Count);
activity?.Stop();
LogTrace($"OdlByBatch | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
return result;
return await GetOrFetchAsync(
operationName: "OdlByBatchAsync",
cacheKey: Utils.redisOdlByBatch,
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.OdlByBatchAsync(BatchSel),
tagList: [Utils.redisOdlByBatch]
);
}
/// <summary>
@@ -1542,16 +1507,16 @@ namespace MP.SPEC.Data
/// </summary>
/// <param name="IdxOdl"></param>
/// <returns></returns>
public ODLExpModel OdlByKey(int IdxOdl)
public async Task<ODLExpModel> OdlByKeyAsync(int IdxOdl)
{
using var activity = ActivitySource.StartActivity("OdlByKey");
ODLExpModel? result = new ODLExpModel();
string source = "DB";
result = dbController.OdlByKey(IdxOdl);
activity?.SetTag("data.source", source);
activity?.Stop();
LogTrace($"OdlByKey | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
return result;
string currKey = $"{Utils.redisOdlByKey}:{IdxOdl}";
return await GetOrFetchAsync(
operationName: "OdlByKeyAsync",
cacheKey: currKey,
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.OdlByKeyAsync(IdxOdl),
tagList: [Utils.redisOdlByKey]
);
}
/// <summary>
@@ -1589,6 +1554,7 @@ namespace MP.SPEC.Data
return fatto;
}
#if false
/// <summary>
/// Record ODL da chaive
/// </summary>
@@ -1602,7 +1568,8 @@ namespace MP.SPEC.Data
activity?.Stop();
LogTrace($"OdlGetByKey | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
return dbResult;
}
}
#endif
/// <summary>
/// Elenco ODL filtrati x stato, articolo, KeyRich (che contiene stato)
+1 -1
View File
@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>MP.SPEC</RootNamespace>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
<UserSecretsId>1800a78a-6ff1-40f9-b490-87fb8bfc1394</UserSecretsId>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
+1 -1
View File
@@ -38,7 +38,7 @@ namespace MP.SPEC.Pages
IdxOdl = int.Parse(_idxOdl.ToString());
}
}
odlExp = MDService.OdlByKey(IdxOdl);
odlExp = await MDService.OdlByKeyAsync(IdxOdl);
}
#endregion Protected Methods
+4 -4
View File
@@ -116,7 +116,7 @@ namespace MP.SPEC.Pages
{
isLoading = true;
await Task.Delay(100);
CurrMSE = await MDService.MseGetAll(true);
CurrMSE = await MDService.MseGetAllAsync(true);
isLoading = false;
}
@@ -146,7 +146,7 @@ namespace MP.SPEC.Pages
}
forceResetSel = true;
var ListMSE = await MDService.MseGetAll(true);
var ListMSE = await MDService.MseGetAllAsync(true);
CurrMachSel = new();
await Task.Delay(250);
await ReloadData();
@@ -197,7 +197,7 @@ namespace MP.SPEC.Pages
await TabDServ.resetMicrostatoMacchina(idxMacc);
}
forceResetSel = true;
var ListMSE = await MDService.MseGetAll(true);
var ListMSE = await MDService.MseGetAllAsync(true);
CurrMachSel = new();
await Task.Delay(250);
await ReloadData();
@@ -211,7 +211,7 @@ namespace MP.SPEC.Pages
private async Task ReloadData()
{
CurrMSE = await MDService.MseGetAll(false);
CurrMSE = await MDService.MseGetAllAsync(false);
SearchFermate = await MDService.AnagEventiGeneralAsync();
}
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo MAPOSPEC </i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>8.16.2605.2908</Version>
<Version>8.16.2605.2909</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 8.16.2605.2908</h4>
<h4>Versione: 8.16.2605.2909</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
8.16.2605.2908
8.16.2605.2909
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>8.16.2605.2908</version>
<version>8.16.2605.2909</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>
+1 -55
View File
@@ -17,44 +17,6 @@ Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCa
- Analisi di `MpDataService.cs` effettuata.
- Identificati i metodi con caching manuale (Redis/DB) e quelli già migrati a `GetOrFetchAsync`.
# Piano di Refactoring: Migrazione a FusionCache in `MpDataService.cs`
Stiamo lavorando sul progetto MP-SPEC.sln, dentro la cartella MP-SPEC (ed i progetti da cui dipende).
Voglio ottimizzare il file Data\MpDataService.cs
## Obiettivo
Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCache` per implementare un approccio multi-layer (Memory + Redis + DB), standardizzando l'accesso ai dati.
## Strategia di Migrazione
- **Metodo Standard**: `GetOrFetchAsync<T>(string operationName, string cacheKey, Func<Task<T>> fetchFunc, TimeSpan expiration, params string[] tagList)`.
- **Invalidazione**: Utilizzare i tag tramite `FlushCacheByTagsAsync`.
## Stato Avanzamento
### Fase 1: Analisi e Mapping (Completata)
- Analisi di `MpDataService.cs` effettuata.
- Identificati i metodi con caching manuale (Redis/DB) e quelli già migrati a `GetOrFetchAsync`.
# Piano di Refactoring: Migrazione a FusionCache in `MpDataService.cs`
Stiamo lavorando sul progetto MP-SPEC.sln, dentro la cartella MP-SPEC (ed i progetti da cui dipende).
Voglio ottimizzare il file Data\MpDataService.cs
## Obiettivo
Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCache` per implementare un approccio multi-layer (Memory + Redis + DB), standardizzando l'accesso ai dati.
## Strategia di Migrazione
- **Metodo Standard**: `GetOrFetchAsync<T>(string operationName, string cacheKey, Func<Task<T>> fetchFunc, TimeSpan expiration, params string[] tagList)`.
- **Invalidazione**: Utilizzare i tag tramite `FlushCacheByTagsAsync`.
## Stato Avanzamento
### Fase 1: Analisi e Mapping (Completata)
- Analisi di `MpDataService.cs` effettuata.
- Identificati i metodi con caching manuale (Redis/DB) e quelli già migrati a `GetOrFetchAsync`.
### Fase 2: Refactoring Metodi di Lettura (Cache-aside) (In corso)
#### ✅ Metodi Migrati (Usano già `GetOrFetchAsync` o `FusionCache.GetOrSet`)
@@ -90,6 +52,7 @@ Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCa
- `TksScoreAsync`
- `WipKitFiltAsync`
- `Traduci` (Migrato con `GetOrSet` su dizionario lingua)
- `MseGetAll` (Migrato con `GetOrFetchAsync`)
#### 🛠️ Metodi da Migrare (Usano ancora Redis/DB manuale)
- [ ] Migrazione di `ActionGetReq` (linea 110: usa `redisDb.StringGetAsync`).
@@ -100,7 +63,6 @@ Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCa
- [ ] Migrazione di `DossiersDeleteRecord` (linea 554: usa `ExecFlushRedisPatternAsync`).
- [ ] Migrazione di `DossiersTakeParamsSnapshotLast` (linea 613: usa `ExecFlushRedisPatternAsync`).
- [ ] Migrazione di `ElencoRepartiDTO` (linea 697: usa `redisDb.StringGet` e `StringSet`).
- [ ] Migrazione di `MseGetAll` (linea 1460: usa `redisDb.StringGet` e `StringSetAsync`).
- [ ] Migrazione di `OdlByBatch` (linea 1512: usa `redisDb.StringGet` e `StringSet`).
- [ ] Migrazione di `OdlByKey` (linea 1546: usa `redisDb.StringGet` e `StringSet`).
- [ ] Migrazione di `PODL_getByKey` (linea 1779: usa `redisDb.StringGet` e `StringSet`).
@@ -120,19 +82,3 @@ Migrare la logica di caching manuale (Redis + DB) verso l'utilizzo di `IFusionCa
- *Mitigazione*: Utilizzare rigorosamente le costanti in `Utils.redis...` per garantire che le chiavi siano identiche o gestite dal nuovo sistema.
- **Rischio**: Errori di serializzazione.
- *Mitigazione*: `FusionCache` gestisce la serializzazione, ma è necessario assicurarsi che i tipi di ritorno siano compatibili con le aspettative dei chiamanti.
### Fase 4: Verifica
- [ ] Verificare la compilazione della soluzione tramite script PowerShell.
- [ ] Controllare che i log (NLog) continuano a riflettere correttamente le operazioni.
## Rischi e Mitigazioni
- **Rischio**: Discrepanza nelle chiavi di cache tra vecchio e nuovo sistema.
- *Mitigazione*: Utilizzare rigorosamente le costanti in `Utils.redis...` per garantire che le chiavi siano identiche o gestite dal nuovo sistema.
- **Rischio**: Errori di serializzazione.
- *Mitigazione*: `FusionCache` gestisce la serializzazione, ma è necessario assicurarsi che i tipi di ritorno siano compatibili con le aspettative dei chiamanti.
### Fase 4: Verifica
- [ ] Verificare la compilazione della soluzione tramite script PowerShell.
- [ ] Controllare che i log (NLog) continuano a riflettere correttamente le operazioni.