Ok gestione eliminazione KIT

This commit is contained in:
Samuele Locatelli
2026-05-30 09:58:24 +02:00
parent 26e8ca0370
commit 79024ddcac
9 changed files with 142 additions and 125 deletions
+56 -25
View File
@@ -1150,20 +1150,28 @@ namespace MP.SPEC.Data
/// <param name="currRecord"></param>
public async Task<bool> IstKitDelete(IstanzeKitModel currRecord)
{
using var activity = ActivitySource.StartActivity("IstKitDelete");
string source = "DB+REDIS";
using var activity = ActivitySource.StartActivity("IstKitDeleteAsync");
string source = "DB";
bool fatto = false;
// salvo
fatto = dbController.IstKitDelete(currRecord);
fatto = await dbController.IstKitDeleteAsync(currRecord);
// svuoto cache
RedisValue pattern = $"{Utils.redisKitInst}:*";
await ExecFlushRedisPatternAsync(pattern);
await FlushKitCache();
activity?.SetTag("data.source", source);
activity?.Stop();
LogTrace($"IstKitDelete | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
LogTrace($"IstKitDeleteAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
return fatto;
}
private async Task FlushKitCache()
{
#if false
RedisValue pattern = $"{Utils.redisKitInst}:*";
await ExecFlushRedisPatternAsync(pattern);
#endif
await FlushCacheByTagsAsync(new List<string>() { Utils.redisPOdlList, Utils.redisKitInst, Utils.redisKitWip, Utils.redisKitScore, Utils.redisPOdlByCodArt });
}
/// <summary>
/// Elenco Istanze KIT da ricerca
/// </summary>
@@ -1195,7 +1203,7 @@ namespace MP.SPEC.Data
// salvo
fatto = await dbController.IstKitInsertByWKSAsync(CodArtParent, KeyFilt);
// svuoto cache
await FlushCacheByTagAsync(Utils.redisPOdlList);
await FlushKitCache();
activity?.SetTag("data.source", source);
activity?.Stop();
LogTrace($"IstKitInsertByWKSAsync | {source} | {activity?.Duration.TotalMilliseconds}ms");
@@ -1208,17 +1216,16 @@ namespace MP.SPEC.Data
/// <param name="currRecord"></param>
public async Task<bool> IstKitUpsert(IstanzeKitModel currRecord)
{
using var activity = ActivitySource.StartActivity("IstKitUpsert");
string source = "DB+REDIS";
using var activity = ActivitySource.StartActivity("IstKitUpsertAsync");
string source = "DB";
bool fatto = false;
// salvo
fatto = dbController.IstKitUpsert(currRecord);
fatto = await dbController.IstKitUpsertAsync(currRecord);
// svuoto cache
RedisValue pattern = $"{Utils.redisKitInst}:*";
await ExecFlushRedisPatternAsync(pattern);
await FlushKitCache();
activity?.SetTag("data.source", source);
activity?.Stop();
LogTrace($"IstKitUpsert | {source} | {activity?.Duration.TotalMilliseconds}ms");
LogTrace($"IstKitUpsertAsync | {source} | {activity?.Duration.TotalMilliseconds}ms");
return fatto;
}
@@ -1245,15 +1252,24 @@ namespace MP.SPEC.Data
/// <param name="CodArticolo"></param>
/// <param name="OnlyAvail">True = aperti (=senza ODL)</param>
/// <returns></returns>
public List<PODLExpModel> ListPODL_ByCodArt(string CodArticolo, bool OnlyAvail)
public async Task<List<PODLExpModel>> ListPODL_ByCodArtAsync(string CodArticolo, bool OnlyAvail)
{
string avType = OnlyAvail ? "Avail" : "ALL";
string currKey = $"{Utils.redisPOdlByCodArt}:{CodArticolo}:{avType}";
return await GetOrFetchAsync(
operationName: "ListPODL_ByCodArtAsync",
cacheKey: currKey,
expiration: getRandTOut(redisLongTimeCache),
fetchFunc: async () => await dbController.ListPODL_ByCodArtAsync(CodArticolo, OnlyAvail) ?? new(),
tagList: [Utils.redisPOdlByCodArt]
);
#if false
List<PODLExpModel> result = new List<PODLExpModel>();
if (!string.IsNullOrEmpty(CodArticolo))
{
using var activity = ActivitySource.StartActivity("ListPODL_ByCodArt");
string source = "DB";
string avType = OnlyAvail ? "Avail" : "ALL";
string currKey = $"{Utils.redisPOdlByCodArt}:{CodArticolo}:{avType}";
// cerco in redis dato valore sel idxMaccSel...
RedisValue rawData = redisDb.StringGet(currKey);
if (rawData.HasValue && rawData.Length() > 2)
@@ -1285,7 +1301,8 @@ namespace MP.SPEC.Data
{
Log.Debug("Errore CodArt vuoto");
}
return result;
return result;
#endif
}
/// <summary>
@@ -1757,19 +1774,22 @@ namespace MP.SPEC.Data
/// Effettua il task di eliminazione PODL KIT + istanze + riattivazione PODL originali disattivate tramite stored
/// </summary>
/// <param name="IdxPODL">IdxPODL parent</param>
public bool PodlIstKitDelete(int IdxPODL)
public async Task<bool> PodlIstKitDeleteAsync(int IdxPODL)
{
using var activity = ActivitySource.StartActivity("PodlIstKitDelete");
using var activity = ActivitySource.StartActivity("PodlIstKitDeleteAsync");
bool fatto = false;
// salvo
fatto = dbController.PodlIstKitDelete(IdxPODL);
fatto = await dbController.PodlIstKitDeleteAsync(IdxPODL);
// svuoto cache
await FlushCacheByTagsAsync(new List<string>() { Utils.redisPOdlList });
#if false
string pattern = $"{Utils.redisKit}:*";
if (!string.IsNullOrEmpty(pattern))
{
ExecFlushRedisPattern(pattern);
}
activity?.SetTag("data.source", "DB+REDIS");
}
#endif
activity?.SetTag("data.source", "DB");
return fatto;
}
@@ -1778,8 +1798,18 @@ namespace MP.SPEC.Data
/// </summary>
/// <param name="IdxPodlParent">IDX PODL parent</param>
/// <returns></returns>
public List<PODLExpModel> POdlListByKitParent(int IdxPodlParent)
public async Task<List<PODLExpModel>> POdlListByKitParentAsync(int IdxPodlParent)
{
string currKey = $"{Utils.redisPOdlList}_kit:ByParent:{IdxPodlParent}";
return await GetOrFetchAsync(
operationName: "POdlListByKitParentAsync",
cacheKey: currKey,
expiration: getRandTOut(redisShortTimeCache),
fetchFunc: async () => await dbController.ListPODL_ByKitParentAsync(IdxPodlParent) ?? new(),
tagList: [Utils.redisPOdlList]
);
#if false
using var activity = ActivitySource.StartActivity("POdlListByKitParent");
List<PODLExpModel>? result = new List<PODLExpModel>();
string source = "DB";
@@ -1793,7 +1823,7 @@ namespace MP.SPEC.Data
}
else
{
result = dbController.ListPODL_ByKitParent(IdxPodlParent);
result = await dbController.ListPODL_ByKitParentAsync(IdxPodlParent);
// serializzo e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(redisShortTimeCache));
@@ -1806,7 +1836,8 @@ namespace MP.SPEC.Data
activity?.SetTag("result.count", result.Count);
activity?.Stop();
LogTrace($"POdlListByKitParent | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
return result;
return result;
#endif
}
/// <summary>