Fix e pulizia metodi ODL
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user