Continuo fix metodi cache x SPEC
This commit is contained in:
+95
-249
@@ -419,32 +419,13 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("ConfigGetAllAsync");
|
||||
string source = "REDIS";
|
||||
List<ConfigModel>? result = new List<ConfigModel>();
|
||||
// cerco in redis...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(Utils.redisConfKey);
|
||||
if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<ConfigModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await dbController.ConfigGetAllAsync();
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(Utils.redisConfKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<ConfigModel>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", result.Count);
|
||||
activity?.Stop();
|
||||
LogTrace($"ConfigGetAllAsync Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "ConfigGetAllAsync",
|
||||
cacheKey: Utils.redisConfKey,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.ConfigGetAllAsync() ?? new List<ConfigModel>(),
|
||||
tagList: [Utils.redisConfKey]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -461,13 +442,6 @@ namespace MP.SPEC.Data
|
||||
LogTrace($"ConfigResetCache Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
}
|
||||
|
||||
private async Task ResetConfigCache()
|
||||
{
|
||||
await redisDb.StringSetAsync(Utils.redisConfKey, "");
|
||||
List<string> tags2del = new List<string>() { Utils.redisConfKey };
|
||||
await FlushCacheByTagsAsync(tags2del);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce valore della stringa (SE disponibile)
|
||||
/// </summary>
|
||||
@@ -593,33 +567,14 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<List<DossierModel>> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("DossiersGetLastFiltAsync");
|
||||
List<DossierModel>? result = new List<DossierModel>();
|
||||
string source = "DB";
|
||||
string currKey = $"{Utils.redisDossByMac}:{IdxMacchina}:{CodArticolo}:{DtStart:yyyyMMddHHmm}:{DtEnd:yyyyMMddHHmm}:{MaxRec}";
|
||||
// cerco in redis dato valore sel idxMaccSel...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<DossierModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await dbController.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache / 5));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<DossierModel>();
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", result.Count);
|
||||
activity?.Stop();
|
||||
LogTrace($"DossiersGetLastFiltAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "DossiersGetLastFiltAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: TimeSpan.FromMinutes(redisLongTimeCache / 5),
|
||||
fetchFunc: async () => await dbController.DossiersGetLastFiltAsync(IdxMacchina, CodArticolo, DtStart, DtEnd, MaxRec) ?? new List<DossierModel>(),
|
||||
tagList: [Utils.redisDossByMac]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1312,42 +1267,6 @@ namespace MP.SPEC.Data
|
||||
return mongoController.InitRecipe(confPath, idxPODL, CalcArgs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero info IOB x TAB (da info registrate IOB-WIN--> MP-IO)
|
||||
/// </summary>
|
||||
/// <param name="IdxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IOB_data> IobInfo(string IdxMacchina)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("IobInfo");
|
||||
string source = "DB";
|
||||
IOB_data? result = new IOB_data();
|
||||
// cerco in redis...
|
||||
string currKey = redHashMpIO($"hM2IOB:{IdxMacchina}");
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
//if (!string.IsNullOrEmpty($"{rawData}"))
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<IOB_data>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"Errore: non trovato valore <IOB_data> valido in REDIS | key: {currKey}");
|
||||
Log.Info($"REDIS | conf: {redisConn.Configuration}");
|
||||
Log.Info($" --> Valore trovato:{Environment.NewLine}{rawData}");
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new IOB_data();
|
||||
LogTrace($"Init valore default <IOB_data> | IdxMacchina: {IdxMacchina}");
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"IobInfo per {IdxMacchina} | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elimina record + svuotamento cache
|
||||
/// </summary>
|
||||
@@ -1923,28 +1842,6 @@ namespace MP.SPEC.Data
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ODL correnti (tutti)
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// elenco TUTTI gli ODL
|
||||
/// </summary>
|
||||
/// <param name="IdxOdl"></param>
|
||||
/// <returns></returns>
|
||||
public List<ODLModel> OdlListAll()
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("OdlListAll");
|
||||
List<ODLModel>? result = new List<ODLModel>();
|
||||
string source = "DB";
|
||||
result = dbController.OdlListAll();
|
||||
activity?.SetTag("data.source", "DB");
|
||||
activity?.Stop();
|
||||
LogTrace($"OdlListAll | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ODL filtrati x stato, articolo, KeyRich (che contiene stato)
|
||||
/// </summary>
|
||||
@@ -2544,28 +2441,6 @@ namespace MP.SPEC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua reset microstato macchina
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
public async Task ResetMicrostatoMacchina(string idxMacchina)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("ResetMicrostatoMacchina");
|
||||
string source = "DB";
|
||||
// salvo microstato 0...
|
||||
MicroStatoMacchinaModel newRecMS = new MicroStatoMacchinaModel()
|
||||
{
|
||||
IdxMacchina = idxMacchina,
|
||||
InizioStato = DateTime.Now,
|
||||
IdxMicroStato = 0,
|
||||
Value = "FER"
|
||||
};
|
||||
var result = await dbController.MicroStatoMacchinaUpsert(newRecMS);
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"ResetMicrostatoMacchina | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statistiche ODL calcolate (da stored stp_STAT_ODL)
|
||||
/// </summary>
|
||||
@@ -2617,37 +2492,6 @@ namespace MP.SPEC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce il valore da REDIS associato al tag richiesto
|
||||
/// </summary>
|
||||
/// <param name="redKey">Chiave in cui cercare il valore</param>
|
||||
/// <returns></returns>
|
||||
public string TagConfGetKey(string redKey)
|
||||
{
|
||||
string outVal = "";
|
||||
using var activity = ActivitySource.StartActivity("TagConfGetKey");
|
||||
string source = "REDIS";
|
||||
// cerco in REDIS la conf x l'IOB
|
||||
var rawData = redisDb.StringGet(redKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
outVal = $"{rawData}";
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"TagConfGetKey | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return outVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco setup dei tag conf correnti
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, List<TagData>> TagsGetAll()
|
||||
{
|
||||
return currTagConf;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elimina record + svuotamento cache
|
||||
/// </summary>
|
||||
@@ -2777,54 +2621,6 @@ namespace MP.SPEC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update valore Dossier
|
||||
/// </summary>
|
||||
/// <param name="currDoss"></param>
|
||||
/// <param name="editFL"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> updateDossierValue(DossierModel currDoss, FluxLogDTO editFL)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("updateDossierValue");
|
||||
string source = "DB";
|
||||
bool answ = false;
|
||||
// recupero intero set valori dossier deserializzando...
|
||||
var fluxLogList = FluxLogDtoGetByFlux(currDoss.Valore);
|
||||
// se tutto ok
|
||||
if (fluxLogList != null)
|
||||
{
|
||||
// da provare...!!!!
|
||||
|
||||
// elimino vecchio record
|
||||
var currRec = fluxLogList.FirstOrDefault(x => x.CodFlux == editFL.CodFlux && x.dtEvento == editFL.dtEvento);
|
||||
if (currRec != null)
|
||||
{
|
||||
fluxLogList.Remove(currRec);
|
||||
// aggiungo nuovo
|
||||
fluxLogList.Add(editFL);
|
||||
}
|
||||
|
||||
// serializzo nuovamente valore
|
||||
DossierFluxLogDTO? result = new DossierFluxLogDTO();
|
||||
var ODLflux = result.ODL.ToList();
|
||||
foreach (var item in fluxLogList)
|
||||
{
|
||||
ODLflux.Add(item);
|
||||
}
|
||||
|
||||
DossierFluxLogDTO updatedResult = new DossierFluxLogDTO() { ODL = ODLflux };
|
||||
|
||||
string rawVal = JsonConvert.SerializeObject(updatedResult);
|
||||
currDoss.Valore = rawVal;
|
||||
// aggiorno record sul DB
|
||||
await dbController.DossiersUpdateValore(currDoss);
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"updateDossierValue | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco completo tabella Vocabolario
|
||||
/// </summary>
|
||||
@@ -2878,25 +2674,6 @@ namespace MP.SPEC.Data
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elimina i record associati al keyFilt indicato
|
||||
/// </summary>
|
||||
/// <param name="KeyFilt"></param>
|
||||
public bool WipKitDeleteGroup(string KeyFilt)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("WipKitDeleteGroup");
|
||||
string source = "DB";
|
||||
bool fatto = false;
|
||||
// salvo
|
||||
fatto = dbController.WipKitDeleteGroup(KeyFilt);
|
||||
// svuoto cache
|
||||
EmptyWipCache();
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"WipKitDeleteGroup Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elimina i record più vecchi della data-ora indicata
|
||||
/// </summary>
|
||||
@@ -2973,18 +2750,6 @@ namespace MP.SPEC.Data
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
|
||||
protected Random rand = new Random();
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected string canCacheParametri { get; set; } = "";
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
@@ -3084,6 +2849,8 @@ namespace MP.SPEC.Data
|
||||
// Cache per controllo eliminazione articoli (Smart HashSet approach)
|
||||
private HashSet<string> _usedArtIdsCache = new();
|
||||
|
||||
private string canCacheParametri = "";
|
||||
|
||||
private string MpIoNS = "";
|
||||
|
||||
/// <summary>
|
||||
@@ -3091,6 +2858,8 @@ namespace MP.SPEC.Data
|
||||
/// </summary>
|
||||
private List<VocabolarioModel> ObjVocabolario = new List<VocabolarioModel>();
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS
|
||||
/// </summary>
|
||||
@@ -3274,6 +3043,83 @@ namespace MP.SPEC.Data
|
||||
activity?.SetTag("data.source", "REDIS");
|
||||
}
|
||||
|
||||
private async Task ResetConfigCache()
|
||||
{
|
||||
await redisDb.StringSetAsync(Utils.redisConfKey, "");
|
||||
List<string> tags2del = new List<string>() { Utils.redisConfKey };
|
||||
await FlushCacheByTagsAsync(tags2del);
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Update valore Dossier
|
||||
/// </summary>
|
||||
/// <param name="currDoss"></param>
|
||||
/// <param name="editFL"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> updateDossierValue(DossierModel currDoss, FluxLogDTO editFL)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("updateDossierValue");
|
||||
string source = "DB";
|
||||
bool answ = false;
|
||||
// recupero intero set valori dossier deserializzando...
|
||||
var fluxLogList = FluxLogDtoGetByFlux(currDoss.Valore);
|
||||
// se tutto ok
|
||||
if (fluxLogList != null)
|
||||
{
|
||||
// da provare...!!!!
|
||||
|
||||
// elimino vecchio record
|
||||
var currRec = fluxLogList.FirstOrDefault(x => x.CodFlux == editFL.CodFlux && x.dtEvento == editFL.dtEvento);
|
||||
if (currRec != null)
|
||||
{
|
||||
fluxLogList.Remove(currRec);
|
||||
// aggiungo nuovo
|
||||
fluxLogList.Add(editFL);
|
||||
}
|
||||
|
||||
// serializzo nuovamente valore
|
||||
DossierFluxLogDTO? result = new DossierFluxLogDTO();
|
||||
var ODLflux = result.ODL.ToList();
|
||||
foreach (var item in fluxLogList)
|
||||
{
|
||||
ODLflux.Add(item);
|
||||
}
|
||||
|
||||
DossierFluxLogDTO updatedResult = new DossierFluxLogDTO() { ODL = ODLflux };
|
||||
|
||||
string rawVal = JsonConvert.SerializeObject(updatedResult);
|
||||
currDoss.Valore = rawVal;
|
||||
// aggiorno record sul DB
|
||||
await dbController.DossiersUpdateValore(currDoss);
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"updateDossierValue | {source} | {activity?.Duration.TotalMilliseconds}ms");
|
||||
return answ;
|
||||
}
|
||||
#endif
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Elimina i record associati al keyFilt indicato
|
||||
/// </summary>
|
||||
/// <param name="KeyFilt"></param>
|
||||
public bool WipKitDeleteGroup(string KeyFilt)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("WipKitDeleteGroup");
|
||||
string source = "DB";
|
||||
bool fatto = false;
|
||||
// salvo
|
||||
fatto = dbController.WipKitDeleteGroup(KeyFilt);
|
||||
// svuoto cache
|
||||
EmptyWipCache();
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.Stop();
|
||||
LogTrace($"WipKitDeleteGroup Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return fatto;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Reset macchine e gruppi
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user