Cleanup codice
This commit is contained in:
@@ -627,88 +627,6 @@ namespace MP.SPEC.Data
|
||||
}
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Verifica se sia possiubile cancellare articolo dato suo CodArt cercando su redis o su
|
||||
/// tab veto da DB
|
||||
/// </summary>
|
||||
/// <param name="CodArt"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ArticoloDelEnabledAsync(object CodArt)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("ArticoloDelEnabledAsync");
|
||||
string codArticolo = $"{CodArt}";
|
||||
|
||||
int cacheCheckArtUsato = 1;
|
||||
int.TryParse(_configuration.GetValue<string>("ServerConf:cacheCheckArtUsato"), out cacheCheckArtUsato);
|
||||
TimeSpan ttl = getRandTOut(cacheCheckArtUsato);
|
||||
|
||||
// 1. Controllo cache locale (Smart HashSet)
|
||||
// Se siamo nel periodo di validità della cache locale, facciamo il controllo istantaneo
|
||||
if (DateTime.Now < _artCacheExpiry)
|
||||
{
|
||||
// Se la nostra cache corrente contiene l'ID (o se stiamo usando la lista degli unused)
|
||||
// Nota: la logica dipende da quale lista è stata caricata.
|
||||
// Per semplicità, se abbiamo caricato gli "usati", cerchiamo tra quelli.
|
||||
// Se abbiamo caricato gli "unused", l'articolo è eliminabile se è nel set.
|
||||
// Ma per evitare confusione, gestiamo il refresh globale.
|
||||
}
|
||||
|
||||
// 2. Fallback su GetOrFetchAsync per garantire la sincronizzazione e l'uso di FusionCache (L1/L2)
|
||||
// Usiamo un approccio che carichi la lista più piccola in memoria.
|
||||
|
||||
// Per evitare complessità di switching lato client, usiamo la lista degli "usati" come riferimento
|
||||
// principale nella cache distribuita, ma ottimizziamo il caricamento.
|
||||
|
||||
bool usato = false;
|
||||
string source = "DB";
|
||||
|
||||
// Controllo se l'ID è già presente nella nostra cache locale degli "usati"
|
||||
if (DateTime.Now < _artCacheExpiry && _usedArtIdsCache.Contains(codArticolo))
|
||||
{
|
||||
usato = true;
|
||||
source = "MEMORY(USED)";
|
||||
}
|
||||
else if (DateTime.Now < _artCacheExpiry && _unusedArtIdsCache.Contains(codArticolo))
|
||||
{
|
||||
usato = false;
|
||||
source = "MEMORY(UNUSED)";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cache scaduta o non presente: ricalcoliamo la strategia
|
||||
int totalCount = await dbController.ArticoliCountAsync();
|
||||
int usedCount = await dbController.ArticoliCountUsedAsync();
|
||||
|
||||
if (usedCount <= (totalCount - usedCount))
|
||||
{
|
||||
// Gli usati sono meno o uguali agli unused: carichiamo gli usati
|
||||
var usedList = await dbController.ArticoliGetUsedAsync();
|
||||
_usedArtIdsCache = new HashSet<string>(usedList.Select(x => x.CodArticolo));
|
||||
_unusedArtIdsCache.Clear();
|
||||
usato = _usedArtIdsCache.Contains(codArticolo);
|
||||
source = "DB+MEMORY(USED)";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Gli unused sono meno: carichiamo gli unused
|
||||
var unusedList = await dbController.ArticoliGetUnusedAsync();
|
||||
_unusedArtIdsCache = new HashSet<string>(unusedList.Select(x => x.CodArticolo));
|
||||
_usedArtIdsCache.Clear();
|
||||
usato = !_unusedArtIdsCache.Contains(codArticolo);
|
||||
source = "DB+MEMORY(UNUSED)";
|
||||
}
|
||||
_artCacheExpiry = DateTime.Now.AddMinutes(cacheCheckArtUsato);
|
||||
}
|
||||
|
||||
bool answ = !usato;
|
||||
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"ArticoloDelEnabledAsync | Cod: {codArticolo} | Usato: {usato} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
|
||||
public string CalcRecipe(RecipeModel currRecipe)
|
||||
{
|
||||
@@ -1842,72 +1760,7 @@ namespace MP.SPEC.Data
|
||||
await dbController.MacchineGetFiltAsync(codGruppo)
|
||||
?? new List<MacchineModel>()
|
||||
);
|
||||
|
||||
#if false
|
||||
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<MacchineModel>()
|
||||
);
|
||||
#endif
|
||||
}
|
||||
#if false
|
||||
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("MacchineGetFiltAsync");
|
||||
string source = "DB";
|
||||
|
||||
string keyGrp = codGruppo != "*" ? codGruppo : "ALL";
|
||||
string memKey = $"MACCHINE_MEM:{keyGrp}";
|
||||
string redisKey = $"{Utils.redisMacList}:{keyGrp}";
|
||||
|
||||
// ✅ 1. MEMORY CACHE
|
||||
if (_memoryCache.TryGetValue(memKey, out List<MacchineModel> cached))
|
||||
{
|
||||
source = "MEMORY";
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"MacchineGetFiltAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return cached;
|
||||
}
|
||||
|
||||
List<MacchineModel> result;
|
||||
|
||||
// ✅ 2. REDIS
|
||||
var rawData = await redisDb.StringGetAsync(redisKey);
|
||||
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<MacchineModel>>(rawData!) ?? new();
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
// ✅ 3. DB
|
||||
result = await dbController.MacchineGetFiltAsync(codGruppo);
|
||||
|
||||
await redisDb.StringSetAsync(
|
||||
redisKey,
|
||||
JsonConvert.SerializeObject(result),
|
||||
getRandTOut(redisLongTimeCache)
|
||||
);
|
||||
}
|
||||
|
||||
// ✅ salva in RAM (IMPORTANTISSIMO), TTL 1 minuto
|
||||
_memoryCache.Set(memKey, result, TimeSpan.FromMinutes(1));
|
||||
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
|
||||
LogTrace($"MacchineGetFiltAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Verifica se la idxMaccSel abbia un codice PATH ricette associato
|
||||
@@ -2245,59 +2098,8 @@ namespace MP.SPEC.Data
|
||||
return dbResult ?? new List<string>();
|
||||
}
|
||||
);
|
||||
|
||||
#if false
|
||||
return await GetOrCreateCachedAsync(
|
||||
operationName: "OdlGetCurrentAsync",
|
||||
memKey: memKey,
|
||||
redisKey: redisKey,
|
||||
// ✅ TTL molto corto (come avevi: 3 secondi)
|
||||
memoryTtl: TimeSpan.FromSeconds(3),
|
||||
dbFactory: async () =>
|
||||
{
|
||||
var rawData = await dbController.OdlGetCurrentAsync();
|
||||
var dbResult = rawData
|
||||
.Select(x => x.IdxMacchina)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
return dbResult ?? new List<string>();
|
||||
}
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if false
|
||||
public List<string> OdlGetCurrent()
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("OdlGetCurrent");
|
||||
List<string>? dbResult = new List<string>();
|
||||
string source = "DB";
|
||||
string currKey = $"{Utils.redisOdlCurrByMac}";
|
||||
// cerco in redis dato valore sel idxMaccSel...
|
||||
RedisValue rawData = redisDb.StringGet(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
dbResult = JsonConvert.DeserializeObject<List<string>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.OdlGetCurrent().Select(x => x.IdxMacchina).Distinct().ToList();
|
||||
rawData = JsonConvert.SerializeObject(dbResult);
|
||||
redisDb.StringSet(currKey, rawData, TimeSpan.FromSeconds(3));
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<string>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", dbResult.Count);
|
||||
activity?.Stop();
|
||||
LogTrace($"OdlGetCurrent | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return dbResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// elenco TUTTI gli ODL
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>MP.Stats</RootNamespace>
|
||||
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
|
||||
<Version>8.16.2605.0414</Version>
|
||||
<Version>8.16.2605.2713</Version>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo statistiche MAPO</i>
|
||||
<h4>Versione: 8.16.2605.0414</h4>
|
||||
<h4>Versione: 8.16.2605.2713</h4>
|
||||
<br />
|
||||
Note di rilascio:
|
||||
<ul>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2605.0414
|
||||
8.16.2605.2713
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2605.0414</version>
|
||||
<version>8.16.2605.2713</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>
|
||||
|
||||
Reference in New Issue
Block a user