Update metodi cache su SPEC
This commit is contained in:
@@ -1377,32 +1377,19 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<string> MacchineRecipeArchiveAsync(string idxMacchina)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("MacchineRecipeArchiveAsync");
|
||||
string? result = "";
|
||||
string source = "DB";
|
||||
string currKey = $"{Utils.redisMacRecipePath}:{idxMacchina}";
|
||||
// cerco in redis dato valore sel idxMaccSel...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<string>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
//recupero elenco macchine...
|
||||
var machineList = await MacchineGetFiltAsync("*");
|
||||
var currMach = machineList.Where(x => x.IdxMacchina == idxMacchina).FirstOrDefault();
|
||||
result = currMach != null ? currMach.RecipeArchivePath : null;
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", 1);
|
||||
activity?.Stop();
|
||||
LogTrace($"MacchineRecipeArchiveAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result ?? "";
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "MacchineRecipeArchiveAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: getRandTOut(redisLongTimeCache),
|
||||
fetchFunc: async () =>
|
||||
{
|
||||
var machineList = await MacchineGetFiltAsync("*");
|
||||
var currMach = machineList.FirstOrDefault(x => x.IdxMacchina == idxMacchina);
|
||||
return currMach?.RecipeArchivePath ?? "";
|
||||
},
|
||||
tagList: [Utils.redisMacRecipePath]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1412,34 +1399,39 @@ namespace MP.SPEC.Data
|
||||
/// <returns></returns>
|
||||
public async Task<string> MacchineRecipeConfAsync(string idxMacchina)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("MacchineRecipeConfAsync");
|
||||
string? result = "";
|
||||
string source = "DB";
|
||||
string currKey = $"{Utils.redisMacRecipeConf}:{idxMacchina}";
|
||||
// cerco in redis dato valore sel idxMaccSel...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<string>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
//recupero elenco macchine...
|
||||
var machineList = await MacchineGetFiltAsync("*");
|
||||
var currMach = machineList.Where(x => x.IdxMacchina == idxMacchina).FirstOrDefault();
|
||||
result = currMach != null ? currMach.RecipePath : null;
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
activity?.SetTag("data.source", source);
|
||||
activity?.SetTag("result.count", 1);
|
||||
activity?.Stop();
|
||||
LogTrace($"MacchineRecipeConfAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms");
|
||||
return result ?? "";
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "MacchineRecipeConfAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: getRandTOut(redisLongTimeCache),
|
||||
fetchFunc: async () =>
|
||||
{
|
||||
var machineList = await MacchineGetFiltAsync("*");
|
||||
var currMach = machineList.FirstOrDefault(x => x.IdxMacchina == idxMacchina);
|
||||
return currMach?.RecipePath ?? "";
|
||||
},
|
||||
tagList: [Utils.redisMacRecipeConf]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco operatori filtrati x gruppo
|
||||
/// </summary>
|
||||
/// <param name="codGruppo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo)
|
||||
{
|
||||
string keyGrp = codGruppo != "*" ? codGruppo : "ALL";
|
||||
string currKey = $"{Utils.redisOprList}:{keyGrp}";
|
||||
|
||||
return await GetOrFetchAsync(
|
||||
operationName: "OperatoriGetFiltAsync",
|
||||
cacheKey: currKey,
|
||||
expiration: getRandTOut(redisLongTimeCache),
|
||||
fetchFunc: async () => await dbController.OperatoriGetFiltAsync(codGruppo) ?? new List<AnagOperatoriModel>(),
|
||||
tagList: [Utils.redisOprList]
|
||||
);
|
||||
}
|
||||
/// <summary>
|
||||
/// Elenco id Macchine che abbiano dati FLuxLog, nel periodo indicato
|
||||
/// </summary>
|
||||
@@ -1725,42 +1717,6 @@ namespace MP.SPEC.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco operatori filtrati x gruppo
|
||||
/// </summary>
|
||||
/// <param name="codGruppo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<AnagOperatoriModel>> OperatoriGetFiltAsync(string codGruppo)
|
||||
{
|
||||
using var activity = ActivitySource.StartActivity("OperatoriGetFiltAsync");
|
||||
List<AnagOperatoriModel>? result = new List<AnagOperatoriModel>();
|
||||
string source = "DB";
|
||||
string keyGrp = codGruppo != "*" ? codGruppo : "ALL";
|
||||
string currKey = $"{Utils.redisOprList}:{keyGrp}";
|
||||
// cerco in redis dato valore sel idxMaccSel...
|
||||
RedisValue rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (rawData.HasValue)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<List<AnagOperatoriModel>>($"{rawData}");
|
||||
source = "REDIS";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await dbController.OperatoriGetFiltAsync(codGruppo);
|
||||
// serializzo e salvo...
|
||||
rawData = JsonConvert.SerializeObject(result);
|
||||
await redisDb.StringSetAsync(currKey, rawData, getRandTOut(redisLongTimeCache));
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = new List<AnagOperatoriModel>();
|
||||
}
|
||||
activity?.SetTag("result.count", result.Count);
|
||||
activity?.Stop();
|
||||
LogTrace($"OperatoriGetFiltAsync | Read from {source}: {activity?.Duration.TotalMilliseconds}ms"); activity?.SetTag("data.source", source);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco di tutti i parametri filtrati x idxMaccSel
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user